diff options
Diffstat (limited to 'libavcodec/libtheoraenc.c')
-rw-r--r-- | libavcodec/libtheoraenc.c | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c index 3990692145..893370fb52 100644 --- a/libavcodec/libtheoraenc.c +++ b/libavcodec/libtheoraenc.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2006 Paul Richards <paul.richards@gmail.com> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -30,7 +30,7 @@ * and o_ prefixes on variables which are libogg types. */ -/* Libav includes */ +/* FFmpeg includes */ #include "libavutil/common.h" #include "libavutil/intreadwrite.h" #include "libavutil/pixdesc.h" @@ -60,21 +60,26 @@ static int concatenate_packet(unsigned int* offset, const char* message = NULL; uint8_t* newdata = NULL; int newsize = avc_context->extradata_size + 2 + packet->bytes; + int ret; if (packet->bytes < 0) { message = "ogg_packet has negative size"; + ret = AVERROR_INVALIDDATA; } else if (packet->bytes > 0xffff) { message = "ogg_packet is larger than 65535 bytes"; + ret = AVERROR_INVALIDDATA; } else if (newsize < avc_context->extradata_size) { message = "extradata_size would overflow"; + ret = AVERROR_INVALIDDATA; } else { newdata = av_realloc(avc_context->extradata, newsize); if (!newdata) message = "av_realloc failed"; + ret = AVERROR(ENOMEM); } if (message) { av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n", message); - return -1; + return ret; } avc_context->extradata = newdata; @@ -96,7 +101,7 @@ static int get_stats(AVCodecContext *avctx, int eos) bytes = th_encode_ctl(h->t_state, TH_ENCCTL_2PASS_OUT, &buf, sizeof(buf)); if (bytes < 0) { av_log(avctx, AV_LOG_ERROR, "Error getting first pass stats\n"); - return -1; + return AVERROR_EXTERNAL; } if (!eos) { h->stats = av_fast_realloc(h->stats, &h->stats_size, @@ -113,7 +118,7 @@ static int get_stats(AVCodecContext *avctx, int eos) return 0; #else av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n"); - return -1; + return AVERROR(ENOSUP); #endif } @@ -127,7 +132,7 @@ static int submit_stats(AVCodecContext *avctx) if (!h->stats) { if (!avctx->stats_in) { av_log(avctx, AV_LOG_ERROR, "No statsfile for second pass\n"); - return -1; + return AVERROR(EINVAL); } h->stats_size = strlen(avctx->stats_in) * 3/4; h->stats = av_malloc(h->stats_size); @@ -139,7 +144,7 @@ static int submit_stats(AVCodecContext *avctx) h->stats_size - h->stats_offset); if (bytes < 0) { av_log(avctx, AV_LOG_ERROR, "Error submitting stats\n"); - return -1; + return AVERROR_EXTERNAL; } if (!bytes) return 0; @@ -148,7 +153,7 @@ static int submit_stats(AVCodecContext *avctx) return 0; #else av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n"); - return -1; + return AVERROR(ENOSUP); #endif } @@ -160,6 +165,7 @@ static av_cold int encode_init(AVCodecContext* avc_context) unsigned int offset; TheoraContext *h = avc_context->priv_data; uint32_t gop_size = avc_context->gop_size; + int ret; /* Set up the theora_info struct */ th_info_init(&t_info); @@ -196,10 +202,9 @@ static av_cold int encode_init(AVCodecContext* avc_context) t_info.pixel_fmt = TH_PF_444; else { av_log(avc_context, AV_LOG_ERROR, "Unsupported pix_fmt\n"); - return -1; + return AVERROR(EINVAL); } - av_pix_fmt_get_chroma_sub_sample(avc_context->pix_fmt, - &h->uv_hshift, &h->uv_vshift); + avcodec_get_chroma_sub_sample(avc_context->pix_fmt, &h->uv_hshift, &h->uv_vshift); if (avc_context->flags & CODEC_FLAG_QSCALE) { /* to be constant with the libvorbis implementation, clip global_quality to 0 - 10 @@ -218,7 +223,7 @@ static av_cold int encode_init(AVCodecContext* avc_context) h->t_state = th_encode_alloc(&t_info); if (!h->t_state) { av_log(avc_context, AV_LOG_ERROR, "theora_encode_init failed\n"); - return -1; + return AVERROR_EXTERNAL; } h->keyframe_mask = (1 << t_info.keyframe_granule_shift) - 1; @@ -228,16 +233,16 @@ static av_cold int encode_init(AVCodecContext* avc_context) if (th_encode_ctl(h->t_state, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE, &gop_size, sizeof(gop_size))) { av_log(avc_context, AV_LOG_ERROR, "Error setting GOP size\n"); - return -1; + return AVERROR_EXTERNAL; } // need to enable 2 pass (via TH_ENCCTL_2PASS_) before encoding headers if (avc_context->flags & CODEC_FLAG_PASS1) { - if (get_stats(avc_context, 0)) - return -1; + if ((ret = get_stats(avc_context, 0)) < 0) + return ret; } else if (avc_context->flags & CODEC_FLAG_PASS2) { - if (submit_stats(avc_context)) - return -1; + if ((ret = submit_stats(avc_context)) < 0) + return ret; } /* @@ -253,8 +258,8 @@ static av_cold int encode_init(AVCodecContext* avc_context) th_comment_init(&t_comment); while (th_encode_flushheader(h->t_state, &t_comment, &o_packet)) - if (concatenate_packet(&offset, avc_context, &o_packet)) - return -1; + if ((ret = concatenate_packet(&offset, avc_context, &o_packet)) < 0) + return ret; th_comment_clear(&t_comment); @@ -276,8 +281,8 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt, if (!frame) { th_encode_packetout(h->t_state, 1, &o_packet); if (avc_context->flags & CODEC_FLAG_PASS1) - if (get_stats(avc_context, 1)) - return -1; + if ((ret = get_stats(avc_context, 1)) < 0) + return ret; return 0; } @@ -290,8 +295,8 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt, } if (avc_context->flags & CODEC_FLAG_PASS2) - if (submit_stats(avc_context)) - return -1; + if ((ret = submit_stats(avc_context)) < 0) + return ret; /* Now call into theora_encode_YUVin */ result = th_encode_ycbcr_in(h->t_state, t_yuv_buffer); @@ -309,12 +314,12 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt, break; } av_log(avc_context, AV_LOG_ERROR, "theora_encode_YUVin failed (%s) [%d]\n", message, result); - return -1; + return AVERROR_EXTERNAL; } if (avc_context->flags & CODEC_FLAG_PASS1) - if (get_stats(avc_context, 0)) - return -1; + if ((ret = get_stats(avc_context, 0)) < 0) + return ret; /* Pick up returned ogg_packet */ result = th_encode_packetout(h->t_state, 0, &o_packet); @@ -327,14 +332,12 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt, break; default: av_log(avc_context, AV_LOG_ERROR, "theora_encode_packetout failed [%d]\n", result); - return -1; + return AVERROR_EXTERNAL; } /* Copy ogg_packet content out to buffer */ - if ((ret = ff_alloc_packet(pkt, o_packet.bytes)) < 0) { - av_log(avc_context, AV_LOG_ERROR, "Error getting output packet of size %ld.\n", o_packet.bytes); + if ((ret = ff_alloc_packet2(avc_context, pkt, o_packet.bytes)) < 0) return ret; - } memcpy(pkt->data, o_packet.packet, o_packet.bytes); // HACK: assumes no encoder delay, this is true until libtheora becomes |