History

avcodec/audiotoolboxenc: Ensure frame_size isn't zero

Zhao Zhili committed 2 years ago

Commit 80cd6e61 parent 338e33b1 file · +21 −3Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/audiotoolboxenc.c+21−3
@@ -92,7 +92,7 @@ static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile) · 91 unmodified lines
9292 }
9393 }
9494
95−static void ffat_update_ctx(AVCodecContext *avctx)
95+static int ffat_update_ctx(AVCodecContext *avctx)
9696 {
9797 ATDecodeContext *at = avctx->priv_data;
9898 UInt32 size = sizeof(unsigned);
@@ -118,10 +118,23 @@ static void ffat_update_ctx(AVCodecContext *avctx) · 19 unmodified lines
118118 if (!AudioConverterGetProperty(at->converter,
119119 kAudioConverterCurrentOutputStreamDescription,
120120 &size, &out_format)) {
121− if (out_format.mFramesPerPacket)
121+ if (out_format.mFramesPerPacket) {
122122 avctx->frame_size = out_format.mFramesPerPacket;
123+ } else {
124+ /* The doc on mFramesPerPacket says:
125+ * For formats with a variable number of frames per packet, such as
126+ * Ogg Vorbis, set this field to 0.
127+ * Looks like it means for decoding. There is no known case that
128+ * mFramesPerPacket is zero for encoding. Use a default value for safety.
129+ */
130+ avctx->frame_size = 1024;
131+ av_log(avctx, AV_LOG_WARNING, "Missing mFramesPerPacket\n");
132+ }
123133 if (out_format.mBytesPerPacket && avctx->codec_id == AV_CODEC_ID_ILBC)
124134 avctx->block_align = out_format.mBytesPerPacket;
135+ } else {
136+ av_log(avctx, AV_LOG_ERROR, "Get OutputStreamDescription failed\n");
137+ return AVERROR_EXTERNAL;
125138 }
126139
127140 at->frame_size = avctx->frame_size;
@@ -130,6 +143,8 @@ static void ffat_update_ctx(AVCodecContext *avctx) · 2 unmodified lines
130143 at->pkt_size *= 1024;
131144 avctx->frame_size *= 1024;
132145 }
146+
147+ return 0;
133148 }
134149
135150 static int read_descr(GetByteContext *gb, int *tag)
@@ -236,6 +251,7 @@ static av_cold int ffat_init_encoder(AVCodecContext *avctx) · 100 unmodified lines
236251 {
237252 ATDecodeContext *at = avctx->priv_data;
238253 OSStatus status;
254+ int ret;
239255
240256 AudioStreamBasicDescription in_format = {
241257 .mSampleRate = avctx->sample_rate,
@@ -432,7 +448,9 @@ static av_cold int ffat_init_encoder(AVCodecContext *avctx) · 190 unmodified lines
432448 }
433449 }
434450
435− ffat_update_ctx(avctx);
451+ ret = ffat_update_ctx(avctx);
452+ if (ret < 0)
453+ return ret;
436454
437455 #if !TARGET_OS_IPHONE && defined(__MAC_10_9)
438456 if (at->mode == kAudioCodecBitRateControlMode_Variable && avctx->rc_max_rate) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t