@@ -331,13 +331,16 @@ static void put_str(AVIOContext *bc, const char *string)
avio_write(bc, string, len);
}
-static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc,
+static int put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc,
const uint8_t *prelude, int prelude_size, uint64_t startcode)
{
uint8_t *dyn_buf = NULL;
int dyn_size = dyn_bc ? avio_get_dyn_buf(dyn_bc, &dyn_buf) : 0;
unsigned forw_ptr = prelude_size + dyn_size + 4;
+ if (dyn_bc && dyn_bc->error < 0)
+ return dyn_bc->error;
+
if (forw_ptr > 4096)
ffio_init_checksum(bc, ff_crc04C11DB7_update, 0);
avio_wb64(bc, startcode);
@@ -354,6 +357,7 @@ static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc,
}
avio_wl32(bc, ffio_get_checksum(bc));
+ return 0;
}
static void write_mainheader(NUTContext *nut, AVIOContext *bc)
@@ -644,28 +648,39 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc)
if (ret < 0)
return ret;
write_mainheader(nut, dyn_bc);
- put_packet(nut, bc, dyn_bc, NULL, 0, MAIN_STARTCODE);
+ ret = put_packet(nut, bc, dyn_bc, NULL, 0, MAIN_STARTCODE);
+ if (ret < 0)
+ goto fail;
for (i = 0; i < nut->avf->nb_streams; i++) {
ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i);
if (ret < 0) {
goto fail;
}
- put_packet(nut, bc, dyn_bc, NULL, 0, STREAM_STARTCODE);
+ ret = put_packet(nut, bc, dyn_bc, NULL, 0, STREAM_STARTCODE);
+ if (ret < 0)
+ goto fail;
}
write_globalinfo(nut, dyn_bc, prelude, &prelude_size);
- put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+ ret = put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+ if (ret < 0)
+ goto fail;
for (i = 0; i < nut->avf->nb_streams; i++) {
ret = write_streaminfo(nut, dyn_bc, i, prelude, &prelude_size);
- if (ret > 0)
- put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+ if (!ret)
+ continue;
+ ret = put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+ if (ret < 0)
+ goto fail;
}
for (i = 0; i < nut->avf->nb_chapters; i++) {
write_chapter(nut, dyn_bc, i, prelude, &prelude_size);
- put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+ ret = put_packet(nut, bc, dyn_bc, prelude, prelude_size, INFO_STARTCODE);
+ if (ret < 0)
+ goto fail;
}
nut->last_syncpoint_pos = INT_MIN;
@@ -1170,11 +1185,11 @@ static int nut_write_trailer(AVFormatContext *s)
if (ret >= 0) {
av_assert1(nut->write_index); // sp_count should be 0 if no index is going to be written
write_index(nut, dyn_bc);
- put_packet(nut, bc, dyn_bc, NULL, 0, INDEX_STARTCODE);
+ ret = put_packet(nut, bc, dyn_bc, NULL, 0, INDEX_STARTCODE);
ffio_free_dyn_buf(&dyn_bc);
}
- return 0;
+ return ret;
}
static void nut_write_deinit(AVFormatContext *s)
For nut_write_trailer() this includes actually returning such errors. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavformat/nutenc.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)