AVFormatWriter: Safeness after avformat_write_header fails
* The ffmpeg documentation explicit forbid to write the trailer when the header write failed. * Fixes #12678.
This commit is contained in:
@@ -381,6 +381,7 @@ AVFormatWriter::AVFormatWriter()
|
|||||||
:
|
:
|
||||||
fContext(avformat_alloc_context()),
|
fContext(avformat_alloc_context()),
|
||||||
fHeaderWritten(false),
|
fHeaderWritten(false),
|
||||||
|
fHeaderError(-1),
|
||||||
fIOContext(NULL),
|
fIOContext(NULL),
|
||||||
fStreamLock("stream lock")
|
fStreamLock("stream lock")
|
||||||
{
|
{
|
||||||
@@ -488,9 +489,9 @@ AVFormatWriter::CommitHeader()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int result = avformat_write_header(fContext, NULL);
|
fHeaderError = avformat_write_header(fContext, NULL);
|
||||||
if (result < 0)
|
if (fHeaderError < 0)
|
||||||
TRACE(" avformat_write_header(): %d\n", result);
|
TRACE(" avformat_write_header(): %d\n", fHeaderError);
|
||||||
|
|
||||||
// We need to close the codecs we opened, even in case of failure.
|
// We need to close the codecs we opened, even in case of failure.
|
||||||
fHeaderWritten = true;
|
fHeaderWritten = true;
|
||||||
@@ -505,7 +506,7 @@ AVFormatWriter::CommitHeader()
|
|||||||
}
|
}
|
||||||
#endif // TRACE_AVFORMAT_WRITER
|
#endif // TRACE_AVFORMAT_WRITER
|
||||||
|
|
||||||
return result == 0 ? B_OK : B_ERROR;
|
return fHeaderError == 0 ? B_OK : B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -529,10 +530,14 @@ AVFormatWriter::Close()
|
|||||||
if (!fHeaderWritten)
|
if (!fHeaderWritten)
|
||||||
return B_NOT_ALLOWED;
|
return B_NOT_ALLOWED;
|
||||||
|
|
||||||
int result = av_write_trailer(fContext);
|
int result = -1;
|
||||||
if (result < 0)
|
// From ffmpeg documentation: [av_write_trailer] may only be called
|
||||||
TRACE(" av_write_trailer(): %d\n", result);
|
// after a successful call to avformat_write_header.
|
||||||
|
if (fHeaderError > 0) {
|
||||||
|
result = av_write_trailer(fContext);
|
||||||
|
if (result < 0)
|
||||||
|
TRACE(" av_write_trailer(): %d\n", result);
|
||||||
|
}
|
||||||
return result == 0 ? B_OK : B_ERROR;
|
return result == 0 ? B_OK : B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ private:
|
|||||||
|
|
||||||
AVFormatContext* fContext;
|
AVFormatContext* fContext;
|
||||||
bool fHeaderWritten;
|
bool fHeaderWritten;
|
||||||
|
int fHeaderError;
|
||||||
|
|
||||||
AVIOContext* fIOContext;
|
AVIOContext* fIOContext;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user