Skip to content

Commit

Permalink
VideoDecoderFFmpeg is final. Other decoders inherit VideoDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed May 23, 2014
1 parent 8c8905c commit 793f633
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 155 deletions.
44 changes: 0 additions & 44 deletions src/QtAV/VideoDecoderFFmpeg.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/QtAV/VideoDecoderFFmpegHW.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#ifndef QTAV_VIDEODECODERFFMPEGHW_H
#define QTAV_VIDEODECODERFFMPEGHW_H

#include <QtAV/VideoDecoderFFmpeg.h>
#include <QtAV/VideoDecoder.h>

namespace QtAV {

class VideoDecoderFFmpegHWPrivate;
class Q_AV_EXPORT VideoDecoderFFmpegHW : public VideoDecoderFFmpeg
class Q_AV_EXPORT VideoDecoderFFmpegHW : public VideoDecoder
{
DPTR_DECLARE_PRIVATE(VideoDecoderFFmpegHW)
public:
Expand Down
6 changes: 3 additions & 3 deletions src/QtAV/private/VideoDecoderFFmpegHW_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef QTAV_VIDEODECODERFFMPEGHW_P_H
#define QTAV_VIDEODECODERFFMPEGHW_P_H

#include "QtAV/private/VideoDecoderFFmpeg_p.h"
#include "QtAV/private/VideoDecoder_p.h"

/*!
QTAV_VA_REF: use AVCodecContext.get_buffer2 instead of old callbacks. In order to avoid compile warnings, now disable old
Expand All @@ -32,11 +32,11 @@

namespace QtAV {

class Q_AV_EXPORT VideoDecoderFFmpegHWPrivate : public VideoDecoderFFmpegPrivate
class Q_AV_EXPORT VideoDecoderFFmpegHWPrivate : public VideoDecoderPrivate
{
public:
VideoDecoderFFmpegHWPrivate()
: VideoDecoderFFmpegPrivate()
: VideoDecoderPrivate()
, va_pixfmt(QTAV_PIX_FMT_C(NONE))
{
get_format = 0;
Expand Down
43 changes: 0 additions & 43 deletions src/QtAV/private/VideoDecoderFFmpeg_p.h

This file was deleted.

43 changes: 41 additions & 2 deletions src/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,47 @@ bool VideoDecoder::prepare()
//TODO: use ipp, cuda decode and yuv functions. is sws_scale necessary?
bool VideoDecoder::decode(const QByteArray &encoded)
{
Q_UNUSED(encoded);
return false;
if (!isAvailable())
return false;
DPTR_D(VideoDecoder);
AVPacket packet;
#if NO_PADDING_DATA
/*!
larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer avpkt->data should be set to 0 to ensure that no overreading happens for damaged MPEG streams
*/
// auto released by av_buffer_default_free
av_new_packet(&packet, encoded.size());
memcpy(packet.data, encoded.data(), encoded.size());
#else
av_init_packet(&packet);
packet.size = encoded.size();
packet.data = (uint8_t*)encoded.constData();
#endif //NO_PADDING_DATA
//TODO: use AVPacket directly instead of Packet?
//AVStream *stream = format_context->streams[stream_idx];

//TODO: some decoders might in addition need other fields like flags&AV_PKT_FLAG_KEY
int ret = avcodec_decode_video2(d.codec_ctx, d.frame, &d.got_frame_ptr, &packet);
//qDebug("pic_type=%c", av_get_picture_type_char(d.frame->pict_type));
d.undecoded_size = qMin(encoded.size() - ret, encoded.size());
//TODO: decoded format is YUV420P, YUV422P?
av_free_packet(&packet);
if (ret < 0) {
qWarning("[VideoDecoder] %s", av_err2str(ret));
return false;
}
if (!d.got_frame_ptr) {
qWarning("no frame could be decompressed: %s", av_err2str(ret));
return true;
}
if (!d.codec_ctx->width || !d.codec_ctx->height)
return false;
//qDebug("codec %dx%d, frame %dx%d", d.codec_ctx->width, d.codec_ctx->height, d.frame->width, d.frame->height);
d.width = d.frame->width;
d.height = d.frame->height;
//avcodec_align_dimensions2(d.codec_ctx, &d.width_align, &d.height_align, aligns);
return true;
}

void VideoDecoder::resizeVideoFrame(const QSize &size)
Expand Down
14 changes: 8 additions & 6 deletions src/VideoDecoderCedarv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/

#include "QtAV/VideoDecoderFFmpeg.h"
#include "private/VideoDecoderFFmpeg_p.h"
#include "QtAV/VideoDecoder.h"
#include "private/VideoDecoder_p.h"
#include <QtAV/Packet.h>
#include <QtAV/QtAV_Compat.h>
#include "prepost.h"
Expand Down Expand Up @@ -293,7 +293,7 @@ static void map32x32_to_yuv_C(unsigned char* srcC,unsigned char* tarCb,unsigned
namespace QtAV {

class VideoDecoderCedarvPrivate;
class VideoDecoderCedarv : public VideoDecoderFFmpeg
class VideoDecoderCedarv : public VideoDecoder
{
DPTR_DECLARE_PRIVATE(VideoDecoderCedarv)
public:
Expand All @@ -315,10 +315,12 @@ void RegisterVideoDecoderCedarv_Man()
FACTORY_REGISTER_ID_MAN(VideoDecoder, Cedarv, "Cedarv")
}

class VideoDecoderCedarvPrivate : public VideoDecoderFFmpegPrivate
class VideoDecoderCedarvPrivate : public VideoDecoderPrivate
{
public:
VideoDecoderCedarvPrivate() {
VideoDecoderCedarvPrivate()
: VideoDecoderPrivate()
{
cedarv = 0;
}

Expand All @@ -331,7 +333,7 @@ class VideoDecoderCedarvPrivate : public VideoDecoderFFmpegPrivate
};

VideoDecoderCedarv::VideoDecoderCedarv()
: VideoDecoderFFmpeg(*new VideoDecoderCedarvPrivate())
: VideoDecoder(*new VideoDecoderCedarvPrivate())
{
}

Expand Down
71 changes: 19 additions & 52 deletions src/VideoDecoderFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/

#include "QtAV/VideoDecoderFFmpeg.h"
#include "QtAV/private/VideoDecoderFFmpeg_p.h"
#include "QtAV/VideoDecoder.h"
#include "QtAV/private/VideoDecoder_p.h"
#include <QtAV/Packet.h>
#include <QtAV/QtAV_Compat.h>
#include "QtAV/prepost.h"

namespace QtAV {

class VideoDecoderFFmpegPrivate;
class VideoDecoderFFmpeg : public VideoDecoder
{
DPTR_DECLARE_PRIVATE(VideoDecoderFFmpeg)
public:
VideoDecoderFFmpeg();
virtual VideoDecoderId id() const;
//virtual bool prepare();
};

extern VideoDecoderId VideoDecoderId_FFmpeg;
FACTORY_REGISTER_ID_AUTO(VideoDecoder, FFmpeg, "FFmpeg")
Expand All @@ -37,65 +46,23 @@ void RegisterVideoDecoderFFmpeg_Man()
}


class VideoDecoderFFmpegPrivate : public VideoDecoderPrivate
{
public:
VideoDecoderFFmpegPrivate():
VideoDecoderPrivate()
{}
};


VideoDecoderFFmpeg::VideoDecoderFFmpeg():
VideoDecoder(*new VideoDecoderFFmpegPrivate())
{
}

VideoDecoderFFmpeg::VideoDecoderFFmpeg(VideoDecoderFFmpegPrivate &d):
VideoDecoder(d)
{
}

VideoDecoderId VideoDecoderFFmpeg::id() const
{
return VideoDecoderId_FFmpeg;
}

bool VideoDecoderFFmpeg::decode(const QByteArray &encoded)
{
if (!isAvailable())
return false;
DPTR_D(VideoDecoderFFmpeg);
AVPacket packet;
#if NO_PADDING_DATA
/*!
larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer avpkt->data should be set to 0 to ensure that no overreading happens for damaged MPEG streams
*/
// auto released by av_buffer_default_free
av_new_packet(&packet, encoded.size());
memcpy(packet.data, encoded.data(), encoded.size());
#else
av_init_packet(&packet);
packet.size = encoded.size();
packet.data = (uint8_t*)encoded.constData();
#endif //NO_PADDING_DATA
//TODO: use AVPacket directly instead of Packet?
//AVStream *stream = format_context->streams[stream_idx];

//TODO: some decoders might in addition need other fields like flags&AV_PKT_FLAG_KEY
int ret = avcodec_decode_video2(d.codec_ctx, d.frame, &d.got_frame_ptr, &packet);
//qDebug("pic_type=%c", av_get_picture_type_char(d.frame->pict_type));
d.undecoded_size = qMin(encoded.size() - ret, encoded.size());
//TODO: decoded format is YUV420P, YUV422P?
av_free_packet(&packet);
if (ret < 0) {
qWarning("[VideoDecoder] %s", av_err2str(ret));
return false;
}
if (!d.got_frame_ptr) {
qWarning("no frame could be decompressed: %s", av_err2str(ret));
return true;
}
if (!d.codec_ctx->width || !d.codec_ctx->height)
return false;
//qDebug("codec %dx%d, frame %dx%d", d.codec_ctx->width, d.codec_ctx->height, d.frame->width, d.frame->height);
d.width = d.frame->width;
d.height = d.frame->height;
//avcodec_align_dimensions2(d.codec_ctx, &d.width_align, &d.height_align, aligns);
return true;
}

} //namespace QtAV
2 changes: 1 addition & 1 deletion src/VideoDecoderFFmpegHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ AVPixelFormat VideoDecoderFFmpegHWPrivate::getFormat(struct AVCodecContext *p_co
}

VideoDecoderFFmpegHW::VideoDecoderFFmpegHW(VideoDecoderFFmpegHWPrivate &d):
VideoDecoderFFmpeg(d)
VideoDecoder(d)
{
}

Expand Down
2 changes: 0 additions & 2 deletions src/libQtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ HEADERS *= \
QtAV/private/GraphicsItemRenderer_p.h \
QtAV/private/ImageConverter_p.h \
QtAV/private/VideoDecoder_p.h \
QtAV/private/VideoDecoderFFmpeg_p.h \
QtAV/private/VideoDecoderFFmpegHW_p.h \
QtAV/VideoDecoderFFmpeg.h \
QtAV/VideoDecoderFFmpegHW.h \
QtAV/private/VideoRenderer_p.h \
QtAV/private/QPainterRenderer_p.h \
Expand Down

0 comments on commit 793f633

Please sign in to comment.