FFMPEG Plugin: Code styles, typos and code deduplication.

- Kudos to stippi for taking the time pointing those out :)
  http://www.freelists.org/post/haiku-commits/haiku-hrev47576-srcaddonsmediapluginsffmpeg,1
- No functional change intended.

Signed-off-by: Colin Günther <[email protected]>
This commit is contained in:
Colin Günther
2014-07-29 17:54:04 +02:00
parent ca21718e14
commit f345d82773
2 changed files with 95 additions and 86 deletions
@@ -254,9 +254,7 @@ AVCodecDecoder::SeekedTo(int64 frame, bigtime_t time)
// Reset the FFmpeg codec to flush buffers, so we keep the sync // Reset the FFmpeg codec to flush buffers, so we keep the sync
if (fCodecInitDone) { if (fCodecInitDone) {
avcodec_flush_buffers(fContext); avcodec_flush_buffers(fContext);
av_init_packet(&fTempPacket); _ResetTempPacket();
fTempPacket.size = 0;
fTempPacket.data = NULL;
} }
// Flush internal buffers as well. // Flush internal buffers as well.
@@ -318,6 +316,15 @@ AVCodecDecoder::Decode(void* outBuffer, int64* outFrameCount,
// #pragma mark - // #pragma mark -
void
AVCodecDecoder::_ResetTempPacket()
{
av_init_packet(&fTempPacket);
fTempPacket.size = 0;
fTempPacket.data = NULL;
}
status_t status_t
AVCodecDecoder::_NegotiateAudioOutputFormat(media_format* inOutFormat) AVCodecDecoder::_NegotiateAudioOutputFormat(media_format* inOutFormat)
{ {
@@ -404,7 +411,7 @@ AVCodecDecoder::_NegotiateAudioOutputFormat(media_format* inOutFormat)
fOutputBufferOffset = 0; fOutputBufferOffset = 0;
fOutputBufferSize = 0; fOutputBufferSize = 0;
av_init_packet(&fTempPacket); _ResetTempPacket();
inOutFormat->require_flags = 0; inOutFormat->require_flags = 0;
inOutFormat->deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS; inOutFormat->deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
@@ -435,7 +442,9 @@ AVCodecDecoder::_NegotiateVideoOutputFormat(media_format* inOutFormat)
fContext->extradata = (uint8_t*)fExtraData; fContext->extradata = (uint8_t*)fExtraData;
fContext->extradata_size = fExtraDataSize; fContext->extradata_size = fExtraDataSize;
if (fCodec->capabilities & CODEC_CAP_TRUNCATED) { bool codecCanHandleIncompleteFrames
= (fCodec->capabilities & CODEC_CAP_TRUNCATED) != 0;
if (codecCanHandleIncompleteFrames) {
// Expect and handle video frames to be splitted across consecutive // Expect and handle video frames to be splitted across consecutive
// data chunks. // data chunks.
fContext->flags |= CODEC_FLAG_TRUNCATED; fContext->flags |= CODEC_FLAG_TRUNCATED;
@@ -522,9 +531,7 @@ AVCodecDecoder::_NegotiateVideoOutputFormat(media_format* inOutFormat)
inOutFormat->require_flags = 0; inOutFormat->require_flags = 0;
inOutFormat->deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS; inOutFormat->deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;
av_init_packet(&fTempPacket); _ResetTempPacket();
fTempPacket.size = 0;
fTempPacket.data = NULL;
#ifdef TRACE_AV_CODEC #ifdef TRACE_AV_CODEC
char buffer[1024]; char buffer[1024];
@@ -736,7 +743,7 @@ AVCodecDecoder::_DecodeNextVideoFrame()
if (fTempPacket.size == 0) { if (fTempPacket.size == 0) {
// Our packet buffer is empty, so fill it now. // Our packet buffer is empty, so fill it now.
status_t getNextChunkStatus = GetNextChunk(&fChunkBuffer, status_t getNextChunkStatus = GetNextChunk(&fChunkBuffer,
&fChunkBufferSize, &chunkMediaHeader); &fChunkBufferSize, &chunkMediaHeader);
if (getNextChunkStatus != B_OK) { if (getNextChunkStatus != B_OK) {
TRACE("AVCodecDecoder::_DecodeNextVideoFrame(): error from " TRACE("AVCodecDecoder::_DecodeNextVideoFrame(): error from "
@@ -885,7 +892,7 @@ AVCodecDecoder::_DecodeNextVideoFrame()
updated fHeader. updated fHeader.
4. There will be at maximumn only one decoded video frame in our cache 4. There will be at maximumn only one decoded video frame in our cache
at any single point in time. Otherwise you couldn't tell to which at any single point in time. Otherwise you couldn't tell to which
cached decoded video frame te properties in fHeader relate to. cached decoded video frame the properties in fHeader relate to.
*/ */
void void
AVCodecDecoder::_UpdateMediaHeaderForVideoFrame() AVCodecDecoder::_UpdateMediaHeaderForVideoFrame()
@@ -926,102 +933,102 @@ AVCodecDecoder::_UpdateMediaHeaderForVideoFrame()
void void
AVCodecDecoder::_DeinterlaceAndColorConvertVideoFrame() AVCodecDecoder::_DeinterlaceAndColorConvertVideoFrame()
{ {
int width = fOutputVideoFormat.display.line_width; int width = fOutputVideoFormat.display.line_width;
int height = fOutputVideoFormat.display.line_count; int height = fOutputVideoFormat.display.line_count;
AVPicture deinterlacedPicture; AVPicture deinterlacedPicture;
bool useDeinterlacedPicture = false; bool useDeinterlacedPicture = false;
if (fRawDecodedPicture->interlaced_frame) { if (fRawDecodedPicture->interlaced_frame) {
AVPicture rawPicture; AVPicture rawPicture;
rawPicture.data[0] = fRawDecodedPicture->data[0]; rawPicture.data[0] = fRawDecodedPicture->data[0];
rawPicture.data[1] = fRawDecodedPicture->data[1]; rawPicture.data[1] = fRawDecodedPicture->data[1];
rawPicture.data[2] = fRawDecodedPicture->data[2]; rawPicture.data[2] = fRawDecodedPicture->data[2];
rawPicture.data[3] = fRawDecodedPicture->data[3]; rawPicture.data[3] = fRawDecodedPicture->data[3];
rawPicture.linesize[0] = fRawDecodedPicture->linesize[0]; rawPicture.linesize[0] = fRawDecodedPicture->linesize[0];
rawPicture.linesize[1] = fRawDecodedPicture->linesize[1]; rawPicture.linesize[1] = fRawDecodedPicture->linesize[1];
rawPicture.linesize[2] = fRawDecodedPicture->linesize[2]; rawPicture.linesize[2] = fRawDecodedPicture->linesize[2];
rawPicture.linesize[3] = fRawDecodedPicture->linesize[3]; rawPicture.linesize[3] = fRawDecodedPicture->linesize[3];
avpicture_alloc(&deinterlacedPicture, avpicture_alloc(&deinterlacedPicture,
fContext->pix_fmt, width, height); fContext->pix_fmt, width, height);
if (avpicture_deinterlace(&deinterlacedPicture, &rawPicture, if (avpicture_deinterlace(&deinterlacedPicture, &rawPicture,
fContext->pix_fmt, width, height) < 0) { fContext->pix_fmt, width, height) < 0) {
TRACE("[v] avpicture_deinterlace() - error\n"); TRACE("[v] avpicture_deinterlace() - error\n");
} else } else
useDeinterlacedPicture = true; useDeinterlacedPicture = true;
} }
// Some decoders do not set pix_fmt until they have decoded 1 frame // Some decoders do not set pix_fmt until they have decoded 1 frame
#if USE_SWS_FOR_COLOR_SPACE_CONVERSION #if USE_SWS_FOR_COLOR_SPACE_CONVERSION
if (fSwsContext == NULL) { if (fSwsContext == NULL) {
fSwsContext = sws_getContext(fContext->width, fContext->height, fSwsContext = sws_getContext(fContext->width, fContext->height,
fContext->pix_fmt, fContext->width, fContext->height, fContext->pix_fmt, fContext->width, fContext->height,
colorspace_to_pixfmt(fOutputVideoFormat.display.format),
SWS_FAST_BILINEAR, NULL, NULL, NULL);
}
#else
if (fFormatConversionFunc == NULL) {
fFormatConversionFunc = resolve_colorspace(
fOutputVideoFormat.display.format, fContext->pix_fmt,
fContext->width, fContext->height);
}
#endif
fDecodedDataSizeInBytes = avpicture_get_size(
colorspace_to_pixfmt(fOutputVideoFormat.display.format), colorspace_to_pixfmt(fOutputVideoFormat.display.format),
SWS_FAST_BILINEAR, NULL, NULL, NULL);
}
#else
if (fFormatConversionFunc == NULL) {
fFormatConversionFunc = resolve_colorspace(
fOutputVideoFormat.display.format, fContext->pix_fmt,
fContext->width, fContext->height); fContext->width, fContext->height);
}
#endif
if (fDecodedData == NULL) fDecodedDataSizeInBytes = avpicture_get_size(
fDecodedData colorspace_to_pixfmt(fOutputVideoFormat.display.format),
= static_cast<uint8_t*>(malloc(fDecodedDataSizeInBytes)); fContext->width, fContext->height);
fPostProcessedDecodedPicture->data[0] = fDecodedData; if (fDecodedData == NULL)
fPostProcessedDecodedPicture->linesize[0] fDecodedData
= fOutputVideoFormat.display.bytes_per_row; = static_cast<uint8_t*>(malloc(fDecodedDataSizeInBytes));
fPostProcessedDecodedPicture->data[0] = fDecodedData;
fPostProcessedDecodedPicture->linesize[0]
= fOutputVideoFormat.display.bytes_per_row;
#if USE_SWS_FOR_COLOR_SPACE_CONVERSION #if USE_SWS_FOR_COLOR_SPACE_CONVERSION
if (fSwsContext != NULL) { if (fSwsContext != NULL) {
#else #else
if (fFormatConversionFunc != NULL) { if (fFormatConversionFunc != NULL) {
#endif #endif
if (useDeinterlacedPicture) { if (useDeinterlacedPicture) {
AVFrame deinterlacedFrame; AVFrame deinterlacedFrame;
deinterlacedFrame.data[0] = deinterlacedPicture.data[0]; deinterlacedFrame.data[0] = deinterlacedPicture.data[0];
deinterlacedFrame.data[1] = deinterlacedPicture.data[1]; deinterlacedFrame.data[1] = deinterlacedPicture.data[1];
deinterlacedFrame.data[2] = deinterlacedPicture.data[2]; deinterlacedFrame.data[2] = deinterlacedPicture.data[2];
deinterlacedFrame.data[3] = deinterlacedPicture.data[3]; deinterlacedFrame.data[3] = deinterlacedPicture.data[3];
deinterlacedFrame.linesize[0] deinterlacedFrame.linesize[0]
= deinterlacedPicture.linesize[0]; = deinterlacedPicture.linesize[0];
deinterlacedFrame.linesize[1] deinterlacedFrame.linesize[1]
= deinterlacedPicture.linesize[1]; = deinterlacedPicture.linesize[1];
deinterlacedFrame.linesize[2] deinterlacedFrame.linesize[2]
= deinterlacedPicture.linesize[2]; = deinterlacedPicture.linesize[2];
deinterlacedFrame.linesize[3] deinterlacedFrame.linesize[3]
= deinterlacedPicture.linesize[3]; = deinterlacedPicture.linesize[3];
#if USE_SWS_FOR_COLOR_SPACE_CONVERSION #if USE_SWS_FOR_COLOR_SPACE_CONVERSION
sws_scale(fSwsContext, deinterlacedFrame.data, sws_scale(fSwsContext, deinterlacedFrame.data,
deinterlacedFrame.linesize, 0, fContext->height, deinterlacedFrame.linesize, 0, fContext->height,
fPostProcessedDecodedPicture->data, fPostProcessedDecodedPicture->data,
fPostProcessedDecodedPicture->linesize); fPostProcessedDecodedPicture->linesize);
#else #else
(*fFormatConversionFunc)(&deinterlacedFrame, (*fFormatConversionFunc)(&deinterlacedFrame,
fPostProcessedDecodedPicture, width, height); fPostProcessedDecodedPicture, width, height);
#endif #endif
} else { } else {
#if USE_SWS_FOR_COLOR_SPACE_CONVERSION #if USE_SWS_FOR_COLOR_SPACE_CONVERSION
sws_scale(fSwsContext, fRawDecodedPicture->data, sws_scale(fSwsContext, fRawDecodedPicture->data,
fRawDecodedPicture->linesize, 0, fContext->height, fRawDecodedPicture->linesize, 0, fContext->height,
fPostProcessedDecodedPicture->data, fPostProcessedDecodedPicture->data,
fPostProcessedDecodedPicture->linesize); fPostProcessedDecodedPicture->linesize);
#else #else
(*fFormatConversionFunc)(fRawDecodedPicture, (*fFormatConversionFunc)(fRawDecodedPicture,
fPostProcessedDecodedPicture, width, height); fPostProcessedDecodedPicture, width, height);
#endif #endif
}
} }
}
if (fRawDecodedPicture->interlaced_frame) if (fRawDecodedPicture->interlaced_frame)
avpicture_free(&deinterlacedPicture); avpicture_free(&deinterlacedPicture);
} }
@@ -48,6 +48,8 @@ public:
private: private:
void _ResetTempPacket();
status_t _NegotiateAudioOutputFormat( status_t _NegotiateAudioOutputFormat(
media_format* inOutFormat); media_format* inOutFormat);