Miam-Player  0.8.0
A nice music player
AVDecoder_p.h
Go to the documentation of this file.
1 /******************************************************************************
2  QtAV: Multimedia framework based on Qt and FFmpeg
3  Copyright (C) 2012-2015 Wang Bin <wbsecg1@gmail.com>
4 
5 * This file is part of QtAV
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ******************************************************************************/
21 
22 #ifndef QTAV_AVDECODER_P_H
23 #define QTAV_AVDECODER_P_H
24 
25 #include <QtCore/QHash>
26 #include <QtCore/QSharedPointer>
27 #include <QtCore/QVector>
28 #include "QtAV/QtAV_Global.h"
29 #include "QtAV/private/AVCompat.h"
30 
31 namespace QtAV {
32 
33 // always define the class to avoid macro check when using it
35 #if QTAV_HAVE(AVBUFREF)
36  QVector<AVBufferRef*> buf;
37 #endif
38 public:
40  Q_UNUSED(frame);
41 #if QTAV_HAVE(AVBUFREF)
42  if (!frame->buf[0]) { //not ref counted. duplicate data?
43  return;
44  }
45 
46  buf.reserve(frame->nb_extended_buf + FF_ARRAY_ELEMS(frame->buf));
47  buf.resize(frame->nb_extended_buf + FF_ARRAY_ELEMS(frame->buf));
48  for (int i = 0; i < (int)FF_ARRAY_ELEMS(frame->buf); ++i) {
49  if (!frame->buf[i]) //so not use planes + nb_extended_buf!
50  continue;
51  buf[i] = av_buffer_ref(frame->buf[i]);
52  if (!buf[i]) {
53  qWarning("av_buffer_ref(frame->buf[%d]) error", i);
54  }
55  }
56  if (!frame->extended_buf)
57  return;
58  for (int i = 0; i < frame->nb_extended_buf; ++i) {
59  const int k = buf.size() + i - frame->nb_extended_buf;
60  buf[k] = av_buffer_ref(frame->extended_buf[i]);
61  if (!buf[k]) {
62  qWarning("av_buffer_ref(frame->extended_buf[%d]) error", i);
63  }
64  }
65 #endif //QTAV_HAVE(AVBUFREF)
66  }
68 #if QTAV_HAVE(AVBUFREF)
69  foreach (AVBufferRef* b, buf) {
70  av_buffer_unref(&b);
71  }
72 #endif //QTAV_HAVE(AVBUFREF)
73  }
74 };
75 typedef QSharedPointer<AVFrameBuffers> AVFrameBuffersRef;
76 
78 {
79 public:
80  static const char* getProfileName(AVCodecID id, int profile) {
82  if (!c)
83  return "Unknow";
84  return av_get_profile_name(c, profile);
85  }
86  static const char* getProfileName(const AVCodecContext* ctx) {
87  if (ctx->codec)
88  return av_get_profile_name(ctx->codec, ctx->profile);
89  return getProfileName(ctx->codec_id, ctx->profile);
90  }
91 
93  codec_ctx(0)
94  , available(true)
95  , is_open(false)
96  , undecoded_size(0)
97  , dict(0)
98  {
99  codec_ctx = avcodec_alloc_context3(NULL);
100  }
101  virtual ~AVDecoderPrivate() {
102  if (dict) {
103  av_dict_free(&dict);
104  }
105  if (codec_ctx) {
106  avcodec_free_context(&codec_ctx);
107  }
108  }
109  virtual bool open() {return true;}
110  virtual void close() {}
111  virtual bool enableFrameRef() const { return true;}
112  void applyOptionsForDict();
113  void applyOptionsForContext();
114 
115  AVCodecContext *codec_ctx; //set once and not change
116  bool available; //TODO: true only when context(and hw ctx) is ready
117  bool is_open;
119  QString codec_name;
120  QVariantHash options;
122 };
123 
124 class AudioResampler;
126 {
127 public:
129  virtual ~AudioDecoderPrivate();
130 
132  QByteArray decoded;
133 };
134 
136 {
137 public:
140  {}
141  virtual ~VideoDecoderPrivate() {}
142 };
143 } //namespace QtAV
144 
145 Q_DECLARE_METATYPE(QtAV::AVFrameBuffersRef)
146 
147 #endif // QTAV_AVDECODER_P_H
void av_buffer_unref(AVBufferRef **buf)
QByteArray decoded
Definition: AVDecoder_p.h:132
Definition: buffer.h:81
bool available
Definition: AVDecoder_p.h:116
AVBufferRef ** extended_buf
Definition: frame.h:381
Definition: frame.h:184
virtual void close()
Definition: AVDecoder_p.h:110
AudioResampler * resampler
Definition: AVDecoder_p.h:131
QSharedPointer< AVFrameBuffers > AVFrameBuffersRef
Definition: AVDecoder_p.h:75
#define Q_AV_PRIVATE_EXPORT
Definition: QtAV_Global.h:43
~AVFrameBuffers()
Definition: AVDecoder_p.h:67
AVCodecContext * codec_ctx
Definition: AVDecoder_p.h:115
enum AVCodecID codec_id
Definition: avcodec.h:1693
const struct AVCodec * codec
Definition: avcodec.h:1685
AVCodecID
Definition: avcodec.h:191
bool is_open
Definition: AVDecoder_p.h:117
struct AVDictionary AVDictionary
Definition: dict.h:90
void av_dict_free(AVDictionary **m)
VideoDecoderPrivate()
Definition: AVDecoder_p.h:138
static const char * getProfileName(AVCodecID id, int profile)
Definition: AVDecoder_p.h:80
QString codec_name
Definition: AVDecoder_p.h:119
Definition: AVDecoder_p.h:34
Definition: AVDecoder_p.h:77
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
int undecoded_size
Definition: AVDecoder_p.h:118
int profile
Definition: avcodec.h:3182
Definition: AudioResampler.h:32
#define FF_ARRAY_ELEMS(a)
Definition: common.h:100
const char * av_get_profile_name(const AVCodec *codec, int profile)
void avcodec_free_context(AVCodecContext **avctx)
Definition: avcodec.h:1676
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Definition: dptr.h:123
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
Definition: frame.h:367
int nb_extended_buf
Definition: frame.h:385
static const char * getProfileName(const AVCodecContext *ctx)
Definition: AVDecoder_p.h:86
AVDictionary * dict
Definition: AVDecoder_p.h:121
virtual ~AVDecoderPrivate()
Definition: AVDecoder_p.h:101
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31
virtual bool enableFrameRef() const
Definition: AVDecoder_p.h:111
AVFrameBuffers(AVFrame *frame)
Definition: AVDecoder_p.h:39
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Definition: avcodec.h:3601
virtual ~VideoDecoderPrivate()
Definition: AVDecoder_p.h:141
AVDecoderPrivate()
Definition: AVDecoder_p.h:92
virtual bool open()
Definition: AVDecoder_p.h:109
Definition: AVDecoder_p.h:125
QVariantHash options
Definition: AVDecoder_p.h:120
Definition: AVDecoder_p.h:135