mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
lavc/libtheoraenc: return proper error codes
This commit is contained in:
parent
799d749c77
commit
8cb76ef275
@ -59,21 +59,26 @@ static int concatenate_packet(unsigned int* offset,
|
|||||||
const char* message = NULL;
|
const char* message = NULL;
|
||||||
uint8_t* newdata = NULL;
|
uint8_t* newdata = NULL;
|
||||||
int newsize = avc_context->extradata_size + 2 + packet->bytes;
|
int newsize = avc_context->extradata_size + 2 + packet->bytes;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (packet->bytes < 0) {
|
if (packet->bytes < 0) {
|
||||||
message = "ogg_packet has negative size";
|
message = "ogg_packet has negative size";
|
||||||
|
ret = AVERROR_INVALIDDATA;
|
||||||
} else if (packet->bytes > 0xffff) {
|
} else if (packet->bytes > 0xffff) {
|
||||||
message = "ogg_packet is larger than 65535 bytes";
|
message = "ogg_packet is larger than 65535 bytes";
|
||||||
|
ret = AVERROR_INVALIDDATA;
|
||||||
} else if (newsize < avc_context->extradata_size) {
|
} else if (newsize < avc_context->extradata_size) {
|
||||||
message = "extradata_size would overflow";
|
message = "extradata_size would overflow";
|
||||||
|
ret = AVERROR_INVALIDDATA;
|
||||||
} else {
|
} else {
|
||||||
newdata = av_realloc(avc_context->extradata, newsize);
|
newdata = av_realloc(avc_context->extradata, newsize);
|
||||||
if (!newdata)
|
if (!newdata)
|
||||||
message = "av_realloc failed";
|
message = "av_realloc failed";
|
||||||
|
ret = AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
if (message) {
|
if (message) {
|
||||||
av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n", message);
|
av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n", message);
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
avc_context->extradata = newdata;
|
avc_context->extradata = newdata;
|
||||||
@ -95,7 +100,7 @@ static int get_stats(AVCodecContext *avctx, int eos)
|
|||||||
bytes = th_encode_ctl(h->t_state, TH_ENCCTL_2PASS_OUT, &buf, sizeof(buf));
|
bytes = th_encode_ctl(h->t_state, TH_ENCCTL_2PASS_OUT, &buf, sizeof(buf));
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Error getting first pass stats\n");
|
av_log(avctx, AV_LOG_ERROR, "Error getting first pass stats\n");
|
||||||
return -1;
|
return AVERROR_EXTERNAL;
|
||||||
}
|
}
|
||||||
if (!eos) {
|
if (!eos) {
|
||||||
h->stats = av_fast_realloc(h->stats, &h->stats_size,
|
h->stats = av_fast_realloc(h->stats, &h->stats_size,
|
||||||
@ -112,7 +117,7 @@ static int get_stats(AVCodecContext *avctx, int eos)
|
|||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n");
|
av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n");
|
||||||
return -1;
|
return AVERROR(ENOSUP);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +131,7 @@ static int submit_stats(AVCodecContext *avctx)
|
|||||||
if (!h->stats) {
|
if (!h->stats) {
|
||||||
if (!avctx->stats_in) {
|
if (!avctx->stats_in) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "No statsfile for second pass\n");
|
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_size = strlen(avctx->stats_in) * 3/4;
|
||||||
h->stats = av_malloc(h->stats_size);
|
h->stats = av_malloc(h->stats_size);
|
||||||
@ -138,7 +143,7 @@ static int submit_stats(AVCodecContext *avctx)
|
|||||||
h->stats_size - h->stats_offset);
|
h->stats_size - h->stats_offset);
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Error submitting stats\n");
|
av_log(avctx, AV_LOG_ERROR, "Error submitting stats\n");
|
||||||
return -1;
|
return AVERROR_EXTERNAL;
|
||||||
}
|
}
|
||||||
if (!bytes)
|
if (!bytes)
|
||||||
return 0;
|
return 0;
|
||||||
@ -147,7 +152,7 @@ static int submit_stats(AVCodecContext *avctx)
|
|||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n");
|
av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n");
|
||||||
return -1;
|
return AVERROR(ENOSUP);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +164,7 @@ static av_cold int encode_init(AVCodecContext* avc_context)
|
|||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
TheoraContext *h = avc_context->priv_data;
|
TheoraContext *h = avc_context->priv_data;
|
||||||
uint32_t gop_size = avc_context->gop_size;
|
uint32_t gop_size = avc_context->gop_size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Set up the theora_info struct */
|
/* Set up the theora_info struct */
|
||||||
th_info_init(&t_info);
|
th_info_init(&t_info);
|
||||||
@ -195,7 +201,7 @@ static av_cold int encode_init(AVCodecContext* avc_context)
|
|||||||
t_info.pixel_fmt = TH_PF_444;
|
t_info.pixel_fmt = TH_PF_444;
|
||||||
else {
|
else {
|
||||||
av_log(avc_context, AV_LOG_ERROR, "Unsupported pix_fmt\n");
|
av_log(avc_context, AV_LOG_ERROR, "Unsupported pix_fmt\n");
|
||||||
return -1;
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
avcodec_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);
|
||||||
|
|
||||||
@ -216,7 +222,7 @@ static av_cold int encode_init(AVCodecContext* avc_context)
|
|||||||
h->t_state = th_encode_alloc(&t_info);
|
h->t_state = th_encode_alloc(&t_info);
|
||||||
if (!h->t_state) {
|
if (!h->t_state) {
|
||||||
av_log(avc_context, AV_LOG_ERROR, "theora_encode_init failed\n");
|
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;
|
h->keyframe_mask = (1 << t_info.keyframe_granule_shift) - 1;
|
||||||
@ -226,16 +232,16 @@ static av_cold int encode_init(AVCodecContext* avc_context)
|
|||||||
if (th_encode_ctl(h->t_state, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
|
if (th_encode_ctl(h->t_state, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
|
||||||
&gop_size, sizeof(gop_size))) {
|
&gop_size, sizeof(gop_size))) {
|
||||||
av_log(avc_context, AV_LOG_ERROR, "Error setting GOP size\n");
|
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
|
// need to enable 2 pass (via TH_ENCCTL_2PASS_) before encoding headers
|
||||||
if (avc_context->flags & CODEC_FLAG_PASS1) {
|
if (avc_context->flags & CODEC_FLAG_PASS1) {
|
||||||
if (get_stats(avc_context, 0))
|
if ((ret = get_stats(avc_context, 0)) < 0)
|
||||||
return -1;
|
return ret;
|
||||||
} else if (avc_context->flags & CODEC_FLAG_PASS2) {
|
} else if (avc_context->flags & CODEC_FLAG_PASS2) {
|
||||||
if (submit_stats(avc_context))
|
if ((ret = submit_stats(avc_context)) < 0)
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -251,8 +257,8 @@ static av_cold int encode_init(AVCodecContext* avc_context)
|
|||||||
th_comment_init(&t_comment);
|
th_comment_init(&t_comment);
|
||||||
|
|
||||||
while (th_encode_flushheader(h->t_state, &t_comment, &o_packet))
|
while (th_encode_flushheader(h->t_state, &t_comment, &o_packet))
|
||||||
if (concatenate_packet(&offset, avc_context, &o_packet))
|
if ((ret = concatenate_packet(&offset, avc_context, &o_packet)) < 0)
|
||||||
return -1;
|
return ret;
|
||||||
|
|
||||||
th_comment_clear(&t_comment);
|
th_comment_clear(&t_comment);
|
||||||
|
|
||||||
@ -274,8 +280,8 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt,
|
|||||||
if (!frame) {
|
if (!frame) {
|
||||||
th_encode_packetout(h->t_state, 1, &o_packet);
|
th_encode_packetout(h->t_state, 1, &o_packet);
|
||||||
if (avc_context->flags & CODEC_FLAG_PASS1)
|
if (avc_context->flags & CODEC_FLAG_PASS1)
|
||||||
if (get_stats(avc_context, 1))
|
if ((ret = get_stats(avc_context, 1)) < 0)
|
||||||
return -1;
|
return ret;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,8 +294,8 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (avc_context->flags & CODEC_FLAG_PASS2)
|
if (avc_context->flags & CODEC_FLAG_PASS2)
|
||||||
if (submit_stats(avc_context))
|
if ((ret = submit_stats(avc_context)) < 0)
|
||||||
return -1;
|
return ret;
|
||||||
|
|
||||||
/* Now call into theora_encode_YUVin */
|
/* Now call into theora_encode_YUVin */
|
||||||
result = th_encode_ycbcr_in(h->t_state, t_yuv_buffer);
|
result = th_encode_ycbcr_in(h->t_state, t_yuv_buffer);
|
||||||
@ -307,12 +313,12 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
av_log(avc_context, AV_LOG_ERROR, "theora_encode_YUVin failed (%s) [%d]\n", message, result);
|
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 (avc_context->flags & CODEC_FLAG_PASS1)
|
||||||
if (get_stats(avc_context, 0))
|
if ((ret = get_stats(avc_context, 0)) < 0)
|
||||||
return -1;
|
return ret;
|
||||||
|
|
||||||
/* Pick up returned ogg_packet */
|
/* Pick up returned ogg_packet */
|
||||||
result = th_encode_packetout(h->t_state, 0, &o_packet);
|
result = th_encode_packetout(h->t_state, 0, &o_packet);
|
||||||
@ -325,7 +331,7 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt,
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
av_log(avc_context, AV_LOG_ERROR, "theora_encode_packetout failed [%d]\n", result);
|
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 */
|
/* Copy ogg_packet content out to buffer */
|
||||||
|
Loading…
Reference in New Issue
Block a user