AVFormatWriter: Rename fContext to fFormatContext
* Seriously, this naming is bad.
This commit is contained in:
@@ -76,7 +76,7 @@ public:
|
|||||||
size_t size, uint32 flags);
|
size_t size, uint32 flags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AVFormatContext* fContext;
|
AVFormatContext* fFormatContext;
|
||||||
AVStream* fStream;
|
AVStream* fStream;
|
||||||
AVPacket fPacket;
|
AVPacket fPacket;
|
||||||
// Since different threads may write to the target,
|
// Since different threads may write to the target,
|
||||||
@@ -89,7 +89,7 @@ private:
|
|||||||
AVFormatWriter::StreamCookie::StreamCookie(AVFormatContext* context,
|
AVFormatWriter::StreamCookie::StreamCookie(AVFormatContext* context,
|
||||||
BLocker* streamLock)
|
BLocker* streamLock)
|
||||||
:
|
:
|
||||||
fContext(context),
|
fFormatContext(context),
|
||||||
fStream(NULL),
|
fStream(NULL),
|
||||||
fStreamLock(streamLock)
|
fStreamLock(streamLock)
|
||||||
{
|
{
|
||||||
@@ -110,8 +110,8 @@ AVFormatWriter::StreamCookie::Init(media_format* format,
|
|||||||
|
|
||||||
BAutolock _(fStreamLock);
|
BAutolock _(fStreamLock);
|
||||||
|
|
||||||
fPacket.stream_index = fContext->nb_streams;
|
fPacket.stream_index = fFormatContext->nb_streams;
|
||||||
fStream = avformat_new_stream(fContext, NULL);
|
fStream = avformat_new_stream(fFormatContext, NULL);
|
||||||
fStream->id = fPacket.stream_index;
|
fStream->id = fPacket.stream_index;
|
||||||
|
|
||||||
if (fStream == NULL) {
|
if (fStream == NULL) {
|
||||||
@@ -329,11 +329,11 @@ AVFormatWriter::StreamCookie::WriteChunk(const void* chunkBuffer,
|
|||||||
// more than one stream. For the moment, this crashes in AVPacket
|
// more than one stream. For the moment, this crashes in AVPacket
|
||||||
// shuffling inside libavformat. Maybe if we want to use this, we
|
// shuffling inside libavformat. Maybe if we want to use this, we
|
||||||
// need to allocate a separate AVPacket and copy the chunk buffer.
|
// need to allocate a separate AVPacket and copy the chunk buffer.
|
||||||
int result = av_interleaved_write_frame(fContext, &fPacket);
|
int result = av_interleaved_write_frame(fFormatContext, &fPacket);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
TRACE(" av_interleaved_write_frame(): %d\n", result);
|
TRACE(" av_interleaved_write_frame(): %d\n", result);
|
||||||
#else
|
#else
|
||||||
int result = av_write_frame(fContext, &fPacket);
|
int result = av_write_frame(fFormatContext, &fPacket);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
TRACE(" av_write_frame(): %d\n", result);
|
TRACE(" av_write_frame(): %d\n", result);
|
||||||
#endif
|
#endif
|
||||||
@@ -360,7 +360,7 @@ AVFormatWriter::StreamCookie::AddTrackInfo(uint32 code,
|
|||||||
|
|
||||||
AVFormatWriter::AVFormatWriter()
|
AVFormatWriter::AVFormatWriter()
|
||||||
:
|
:
|
||||||
fContext(avformat_alloc_context()),
|
fFormatContext(avformat_alloc_context()),
|
||||||
fCodecOpened(false),
|
fCodecOpened(false),
|
||||||
fHeaderError(-1),
|
fHeaderError(-1),
|
||||||
fIOContext(NULL),
|
fIOContext(NULL),
|
||||||
@@ -375,7 +375,7 @@ AVFormatWriter::~AVFormatWriter()
|
|||||||
TRACE("AVFormatWriter::~AVFormatWriter\n");
|
TRACE("AVFormatWriter::~AVFormatWriter\n");
|
||||||
|
|
||||||
// Free the streams and close the AVCodecContexts
|
// Free the streams and close the AVCodecContexts
|
||||||
for(unsigned i = 0; i < fContext->nb_streams; i++) {
|
for(unsigned i = 0; i < fFormatContext->nb_streams; i++) {
|
||||||
#if OPEN_CODEC_CONTEXT
|
#if OPEN_CODEC_CONTEXT
|
||||||
// We only need to close the AVCodecContext when we opened it.
|
// We only need to close the AVCodecContext when we opened it.
|
||||||
// This is experimental, see CommitHeader().
|
// This is experimental, see CommitHeader().
|
||||||
@@ -383,13 +383,13 @@ AVFormatWriter::~AVFormatWriter()
|
|||||||
// NOTE: Since the introduction of AVCodecParameters
|
// NOTE: Since the introduction of AVCodecParameters
|
||||||
// I am not sure this logic is correct.
|
// I am not sure this logic is correct.
|
||||||
if (fCodecOpened)
|
if (fCodecOpened)
|
||||||
avcodec_close(fContext->streams[i]->codec);
|
avcodec_close(fFormatContext->streams[i]->codec);
|
||||||
#endif
|
#endif
|
||||||
av_freep(&fContext->streams[i]->codecpar);
|
av_freep(&fFormatContext->streams[i]->codecpar);
|
||||||
av_freep(&fContext->streams[i]);
|
av_freep(&fFormatContext->streams[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
av_free(fContext);
|
av_free(fFormatContext);
|
||||||
av_free(fIOContext->buffer);
|
av_free(fIOContext->buffer);
|
||||||
av_free(fIOContext);
|
av_free(fIOContext);
|
||||||
}
|
}
|
||||||
@@ -417,19 +417,19 @@ AVFormatWriter::Init(const media_file_format* fileFormat)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup I/O hooks. This seems to be enough.
|
// Setup I/O hooks. This seems to be enough.
|
||||||
fContext->pb = fIOContext;
|
fFormatContext->pb = fIOContext;
|
||||||
|
|
||||||
// Set the AVOutputFormat according to fileFormat...
|
// Set the AVOutputFormat according to fileFormat...
|
||||||
fContext->oformat = av_guess_format(fileFormat->short_name,
|
fFormatContext->oformat = av_guess_format(fileFormat->short_name,
|
||||||
fileFormat->file_extension, fileFormat->mime_type);
|
fileFormat->file_extension, fileFormat->mime_type);
|
||||||
if (fContext->oformat == NULL) {
|
if (fFormatContext->oformat == NULL) {
|
||||||
TRACE(" failed to find AVOuputFormat for %s\n",
|
TRACE(" failed to find AVOuputFormat for %s\n",
|
||||||
fileFormat->short_name);
|
fileFormat->short_name);
|
||||||
return B_NOT_SUPPORTED;
|
return B_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE(" found AVOuputFormat for %s: %s\n", fileFormat->short_name,
|
TRACE(" found AVOuputFormat for %s: %s\n", fileFormat->short_name,
|
||||||
fContext->oformat->name);
|
fFormatContext->oformat->name);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -449,15 +449,15 @@ AVFormatWriter::CommitHeader()
|
|||||||
{
|
{
|
||||||
TRACE("AVFormatWriter::CommitHeader\n");
|
TRACE("AVFormatWriter::CommitHeader\n");
|
||||||
|
|
||||||
if (fContext == NULL)
|
if (fFormatContext == NULL)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
|
|
||||||
if (fCodecOpened)
|
if (fCodecOpened)
|
||||||
return B_NOT_ALLOWED;
|
return B_NOT_ALLOWED;
|
||||||
|
|
||||||
#if OPEN_CODEC_CONTEXT
|
#if OPEN_CODEC_CONTEXT
|
||||||
for (unsigned i = 0; i < fContext->nb_streams; i++) {
|
for (unsigned i = 0; i < fFormatContext->nb_streams; i++) {
|
||||||
AVStream* stream = fContext->streams[i];
|
AVStream* stream = fFormatContext->streams[i];
|
||||||
// NOTE: Experimental, this should not be needed. Especially, since
|
// NOTE: Experimental, this should not be needed. Especially, since
|
||||||
// we have no idea (in the future) what CodecID some encoder uses,
|
// we have no idea (in the future) what CodecID some encoder uses,
|
||||||
// it may be an encoder from a different plugin.
|
// it may be an encoder from a different plugin.
|
||||||
@@ -476,14 +476,14 @@ AVFormatWriter::CommitHeader()
|
|||||||
// 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.
|
||||||
fCodecOpened = true;
|
fCodecOpened = true;
|
||||||
|
|
||||||
fHeaderError = avformat_write_header(fContext, NULL);
|
fHeaderError = avformat_write_header(fFormatContext, NULL);
|
||||||
if (fHeaderError < 0)
|
if (fHeaderError < 0)
|
||||||
TRACE(" avformat_write_header(): %d\n", fHeaderError);
|
TRACE(" avformat_write_header(): %d\n", fHeaderError);
|
||||||
|
|
||||||
#ifdef TRACE_AVFORMAT_WRITER
|
#ifdef TRACE_AVFORMAT_WRITER
|
||||||
TRACE(" wrote header\n");
|
TRACE(" wrote header\n");
|
||||||
for (unsigned i = 0; i < fContext->nb_streams; i++) {
|
for (unsigned i = 0; i < fFormatContext->nb_streams; i++) {
|
||||||
AVStream* stream = fContext->streams[i];
|
AVStream* stream = fFormatContext->streams[i];
|
||||||
TRACE(" stream[%u] time_base: (%d/%d), codec->time_base: (%d/%d)\n",
|
TRACE(" stream[%u] time_base: (%d/%d), codec->time_base: (%d/%d)\n",
|
||||||
i, stream->time_base.num, stream->time_base.den,
|
i, stream->time_base.num, stream->time_base.den,
|
||||||
stream->codec->time_base.num, stream->codec->time_base.den);
|
stream->codec->time_base.num, stream->codec->time_base.den);
|
||||||
@@ -508,7 +508,7 @@ AVFormatWriter::Close()
|
|||||||
{
|
{
|
||||||
TRACE("AVFormatWriter::Close\n");
|
TRACE("AVFormatWriter::Close\n");
|
||||||
|
|
||||||
if (fContext == NULL)
|
if (fFormatContext == NULL)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
|
|
||||||
if (!fCodecOpened)
|
if (!fCodecOpened)
|
||||||
@@ -519,7 +519,7 @@ AVFormatWriter::Close()
|
|||||||
if (fHeaderError != 0)
|
if (fHeaderError != 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
int result = av_write_trailer(fContext);
|
int result = av_write_trailer(fFormatContext);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
TRACE(" av_write_trailer(): %d\n", result);
|
TRACE(" av_write_trailer(): %d\n", result);
|
||||||
return result == 0 ? B_OK : B_ERROR;
|
return result == 0 ? B_OK : B_ERROR;
|
||||||
@@ -540,7 +540,7 @@ AVFormatWriter::AllocateCookie(void** _cookie, media_format* format,
|
|||||||
if (_cookie == NULL)
|
if (_cookie == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
StreamCookie* cookie = new(std::nothrow) StreamCookie(fContext,
|
StreamCookie* cookie = new(std::nothrow) StreamCookie(fFormatContext,
|
||||||
&fStreamLock);
|
&fStreamLock);
|
||||||
|
|
||||||
status_t ret = cookie->Init(format, codecInfo);
|
status_t ret = cookie->Init(format, codecInfo);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
class StreamCookie;
|
class StreamCookie;
|
||||||
|
|
||||||
AVFormatContext* fContext;
|
AVFormatContext* fFormatContext;
|
||||||
bool fCodecOpened;
|
bool fCodecOpened;
|
||||||
int fHeaderError;
|
int fHeaderError;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user