Skip to content

Commit

Permalink
dec: remove deprecated AVDecoder.decode(QByteArray)
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Feb 24, 2016
1 parent 1bce2cd commit 03fd8fb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 200 deletions.
1 change: 0 additions & 1 deletion src/QtAV/AVDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Q_AV_EXPORT AVDecoder : public QObject
void* codecContext() const;
/*not available if AVCodecContext == 0*/
bool isAvailable() const;
QTAV_DEPRECATED virtual bool decode(const QByteArray&) { return false;}
virtual bool decode(const Packet& packet) = 0;
int undecodedSize() const; //TODO: remove. always decode whole input data completely

Expand Down
63 changes: 7 additions & 56 deletions src/codec/audio/AudioDecoderFFmpeg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2015 Wang Bin <[email protected]>
Copyright (C) 2012-2016 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -40,18 +40,17 @@ class AudioDecoderFFmpeg : public AudioDecoder
Q_PROPERTY(QString codecName READ codecName WRITE setCodecName NOTIFY codecNameChanged)
public:
AudioDecoderFFmpeg();
AudioDecoderId id() const Q_DECL_FINAL;
virtual QString description() const Q_DECL_FINAL {
AudioDecoderId id() const Q_DECL_OVERRIDE Q_DECL_FINAL;
virtual QString description() const Q_DECL_OVERRIDE Q_DECL_FINAL {
const int patch = QTAV_VERSION_PATCH(avcodec_version());
return QStringLiteral("%1 avcodec %2.%3.%4")
.arg(patch>=100?QStringLiteral("FFmpeg"):QStringLiteral("Libav"))
.arg(QTAV_VERSION_MAJOR(avcodec_version())).arg(QTAV_VERSION_MINOR(avcodec_version())).arg(patch);
}
bool decode(const QByteArray &encoded) Q_DECL_FINAL;
bool decode(const Packet& packet) Q_DECL_FINAL;
AudioFrame frame() Q_DECL_FINAL;
bool decode(const Packet& packet) Q_DECL_OVERRIDE Q_DECL_FINAL;
AudioFrame frame() Q_DECL_OVERRIDE Q_DECL_FINAL;
Q_SIGNALS:
void codecNameChanged();
void codecNameChanged() Q_DECL_OVERRIDE Q_DECL_FINAL;
};

AudioDecoderId AudioDecoderId_FFmpeg = mkid::id32base36_6<'F','F','m','p','e','g'>::value;
Expand Down Expand Up @@ -128,54 +127,6 @@ bool AudioDecoderFFmpeg::decode(const Packet &packet)
return !d.decoded.isEmpty();
}

//
bool AudioDecoderFFmpeg::decode(const QByteArray &encoded)
{
if (!isAvailable())
return false;
DPTR_D(AudioDecoderFFmpeg);
d.decoded.clear();
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
int got_frame_ptr = 0;
int ret = avcodec_decode_audio4(d.codec_ctx, d.frame, &got_frame_ptr, &packet);
d.undecoded_size = qMin(encoded.size() - ret, encoded.size());
av_free_packet(&packet);
if (ret == AVERROR(EAGAIN)) {
return false;
}
if (ret < 0) {
qWarning("[AudioDecoder] %s", av_err2str(ret));
return false;
}
if (!got_frame_ptr) {
qWarning("[AudioDecoder] got_frame_ptr=false. decoded: %d, un: %d", ret, d.undecoded_size);
return true;
}
#if USE_AUDIO_FRAME
return true;
#endif
d.resampler->setInSampesPerChannel(d.frame->nb_samples);
if (!d.resampler->convert((const quint8**)d.frame->extended_data)) {
return false;
}
d.decoded = d.resampler->outData();
return true;
return !d.decoded.isEmpty();
}

AudioFrame AudioDecoderFFmpeg::frame()
{
DPTR_D(AudioDecoderFFmpeg);
Expand All @@ -187,6 +138,7 @@ AudioFrame AudioDecoderFFmpeg::frame()
return AudioFrame();
}
AudioFrame f(fmt);
//av_frame_get_pkt_duration ffmpeg
f.setBits(d.frame->extended_data); // TODO: ref
f.setBytesPerLine(d.frame->linesize[0], 0); // for correct alignment
f.setSamplesPerChannel(d.frame->nb_samples);
Expand All @@ -197,5 +149,4 @@ AudioFrame AudioDecoderFFmpeg::frame()
}

} //namespace QtAV

#include "AudioDecoderFFmpeg.moc"
52 changes: 1 addition & 51 deletions src/codec/video/VideoDecoderCUDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ class VideoDecoderCUDA : public VideoDecoder
VideoDecoderId id() const Q_DECL_OVERRIDE;
QString description() const Q_DECL_OVERRIDE;
void flush() Q_DECL_OVERRIDE;
QTAV_DEPRECATED bool decode(const QByteArray &encoded) Q_DECL_FINAL;
bool decode(const Packet &packet) Q_DECL_OVERRIDE Q_DECL_FINAL;
bool decode(const Packet &packet) Q_DECL_OVERRIDE;
virtual VideoFrame frame() Q_DECL_OVERRIDE;

// properties
Expand Down Expand Up @@ -345,55 +344,6 @@ void VideoDecoderCUDA::flush()
d.surface_in_use.fill(false);
}

bool VideoDecoderCUDA::decode(const QByteArray &encoded)
{
if (!isAvailable())
return false;
DPTR_D(VideoDecoderCUDA);
if (!d.parser) {
qWarning("CUVID parser not ready");
return false;
}
uint8_t *outBuf = 0;
int outBufSize = 0;
// h264_mp4toannexb_filter does not use last parameter 'keyFrame', so just set 0
//return: 0: not changed, no outBuf allocated. >0: ok. <0: fail
int filtered = av_bitstream_filter_filter(d.bitstream_filter_ctx, d.codec_ctx, NULL, &outBuf, &outBufSize
, (const uint8_t*)encoded.constData(), encoded.size()
, 0);//d.is_keyframe);
//qDebug("%s @%d filtered=%d outBuf=%p, outBufSize=%d", __FUNCTION__, __LINE__, filtered, outBuf, outBufSize);
if (filtered < 0) {
qDebug("failed to filter: %s", av_err2str(filtered));
}
unsigned char *payload = outBuf;
unsigned long payload_size = outBufSize;
#if 0 // see ffmpeg.c. FF_INPUT_BUFFER_PADDING_SIZE for alignment issue
QByteArray data_with_pad;
if (filtered > 0) {
data_with_pad.resize(outBufSize + FF_INPUT_BUFFER_PADDING_SIZE);
data_with_pad.fill(0);
memcpy(data_with_pad.data(), outBuf, outBufSize);
payload = (unsigned char*)data_with_pad.constData();
payload_size = data_with_pad.size();
}
#endif
CUVIDSOURCEDATAPACKET cuvid_pkt;
memset(&cuvid_pkt, 0, sizeof(CUVIDSOURCEDATAPACKET));
cuvid_pkt.payload = payload;// (unsigned char *)encoded.constData();
cuvid_pkt.payload_size = payload_size; //encoded.size();
cuvid_pkt.flags = CUVID_PKT_TIMESTAMP;
cuvid_pkt.timestamp = 0;// ?
//TODO: fill NALU header for h264? https://devtalk.nvidia.com/default/topic/515571/what-the-data-format-34-cuvidparsevideodata-34-can-accept-/
d.doParseVideoData(&cuvid_pkt);
if (filtered > 0) {
av_freep(&outBuf);
}
// callbacks are in the same thread as this. so no queue is required?
//qDebug("frame queue size on decode: %d", d.frame_queue.size());
return !d.frame_queue.isEmpty();
// video thread: if dec.hasFrame() keep pkt for the next loop and not decode, direct display the frame
}

bool VideoDecoderCUDA::decode(const Packet &packet)
{
if (!isAvailable())
Expand Down
46 changes: 2 additions & 44 deletions src/codec/video/VideoDecoderCedarv.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013-2015 Wang Bin <[email protected]>
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Miroslav Bendik <[email protected]>
* This file is part of QtAV
* This file is part of QtAV (from 2013)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -65,7 +65,6 @@ class VideoDecoderCedarv : public VideoDecoder
QString description() const Q_DECL_OVERRIDE Q_DECL_FINAL{
return QStringLiteral("Allwinner A10 CedarX video hardware acceleration");
}
bool decode(const QByteArray &encoded) Q_DECL_OVERRIDE Q_DECL_FINAL;
bool decode(const Packet& packet) Q_DECL_OVERRIDE Q_DECL_FINAL;
VideoFrame frame() Q_DECL_OVERRIDE Q_DECL_FINAL;

Expand Down Expand Up @@ -384,47 +383,6 @@ bool VideoDecoderCedarvPrivate::open()
return true;
}

bool VideoDecoderCedarv::decode(const QByteArray &encoded)
{
DPTR_D(VideoDecoderCedarv);
if (encoded.isEmpty())
return true;
//d.cedarv->ioctrl(d.cedarv, CEDARV_COMMAND_JUMP, 0);
u32 bufsize0, bufsize1;
u8 *buf0, *buf1;
int ret = d.cedarv->request_write(d.cedarv, encoded.size(), &buf0, &bufsize0, &buf1, &bufsize1);
if (ret < 0) {
qWarning("CedarV: request_write failed (%d)", ret);
return false;
}
memcpy(buf0, encoded.constData(), bufsize0);
if ((u32)encoded.size() > bufsize0)
memcpy(buf1, encoded.constData() + bufsize0, bufsize1);
cedarv_stream_data_info_t stream_data_info;
stream_data_info.type = 0;
stream_data_info.lengh = encoded.size();
stream_data_info.pts = 0; //packet.pts;
stream_data_info.flags = CEDARV_FLAG_FIRST_PART | CEDARV_FLAG_LAST_PART | CEDARV_FLAG_PTS_VALID;
if ((ret = d.cedarv->update_data(d.cedarv, &stream_data_info)) < 0) {
qWarning("CedarV: update_data failed (%d)", ret);
return false;
}
if ((ret = d.cedarv->decode(d.cedarv)) < 0) {
qWarning("CedarV: decode failed (%d)", ret);
return false;
}
ret = d.cedarv->display_request(d.cedarv, &d.cedarPicture);
if (ret > 3 || ret < 0) {
qWarning("CedarV: display_request failed (%d)", ret);
if (d.cedarPicture.id) {
d.cedarv->display_release(d.cedarv, d.cedarPicture.id);
d.cedarPicture.id = 0;
}
return false;
}
return true;
}

bool VideoDecoderCedarv::decode(const Packet &packet)
{
DPTR_D(VideoDecoderCedarv);
Expand Down
46 changes: 1 addition & 45 deletions src/codec/video/VideoDecoderFFmpegBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,57 +105,13 @@ VideoDecoderFFmpegBase::VideoDecoderFFmpegBase(VideoDecoderFFmpegBasePrivate &d)
VideoDecoder(d)
{
}
// always keep the following code
//TODO: use ipp, cuda decode and yuv functions. is sws_scale necessary?
bool VideoDecoderFFmpegBase::decode(const QByteArray &encoded)
{
if (!isAvailable())
return false;
DPTR_D(VideoDecoderFFmpegBase);
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
int got_frame_ptr = 0;
//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, &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("[VideoDecoderFFmpegBase] %s", av_err2str(ret));
return false;
}
if (!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;
}

bool VideoDecoderFFmpegBase::decode(const Packet &packet)
{
if (!isAvailable())
return false;
DPTR_D(VideoDecoderFFmpegBase);
// some decoders might in addition need other fields like flags&AV_PKT_FLAG_KEY
// some decoders might need other fields like flags&AV_PKT_FLAG_KEY
// const AVPacket*: ffmpeg >= 1.0. no libav
int got_frame_ptr = 0;
int ret = 0;
Expand Down
5 changes: 2 additions & 3 deletions src/codec/video/VideoDecoderFFmpegBase.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2014-2015 Wang Bin <[email protected]>
Copyright (C) 2012-2016 Wang Bin <[email protected]>
* This file is part of QtAV
* This file is part of QtAV (from 2014)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -34,7 +34,6 @@ class VideoDecoderFFmpegBase : public VideoDecoder
Q_DISABLE_COPY(VideoDecoderFFmpegBase)
DPTR_DECLARE_PRIVATE(VideoDecoderFFmpegBase)
public:
QTAV_DEPRECATED virtual bool decode(const QByteArray &encoded) Q_DECL_OVERRIDE;
virtual bool decode(const Packet& packet) Q_DECL_OVERRIDE;
protected:
VideoDecoderFFmpegBase(VideoDecoderFFmpegBasePrivate &d);
Expand Down

0 comments on commit 03fd8fb

Please sign in to comment.