FFMPEG Plugin: Implement and use calculation of bytes per row.

This commit is contained in:
Colin Günther
2014-08-04 12:25:23 +02:00
parent 4f4d98911a
commit 60909c1e19
2 changed files with 39 additions and 3 deletions
@@ -908,7 +908,9 @@ AVCodecDecoder::_UpdateMediaHeaderForVideoFrame()
fHeader.start_time = fRawDecodedPicture->reordered_opaque;
fHeader.u.raw_video.display_line_width = fRawDecodedPicture->width;
fHeader.u.raw_video.display_line_count = fRawDecodedPicture->height;
fHeader.u.raw_video.bytes_per_row = 0; // TODO: Implement calculation
fHeader.u.raw_video.bytes_per_row
= CalculateBytesPerRowWithColorSpaceAndVideoWidth(
fOutputVideoFormat.display.format, fRawDecodedPicture->width);
fHeader.u.raw_video.field_gamma = 1.0;
fHeader.u.raw_video.field_sequence = fFrame;
fHeader.u.raw_video.field_number = 0;
+36 -2
View File
@@ -7,13 +7,15 @@
#define UTILITIES_H
/*! \brief This file contains functions to convert values from FFmpeg to Media
Kit and vice versa.
/*! \brief This file contains functions to convert and calculate values from
FFmpeg to Media Kit and vice versa.
*/
#include <assert.h>
#include <GraphicsDefs.h>
extern "C" {
#include "avcodec.h"
}
@@ -70,5 +72,37 @@ ConvertAVCodecContextToVideoAspectWidthAndHeight(AVCodecContext& contextIn,
}
/*! \brief Calculates bytes per row for a video frame.
\param colorSpace The Media Kit color space the video frame uses.
\param videoWidth The width of the video frame.
\returns bytes per video frame row
\returns Zero, when bytes per video frame cannot be calculated.
*/
inline uint32
CalculateBytesPerRowWithColorSpaceAndVideoWidth(color_space colorSpace, int videoWidth)
{
assert(videoWidth >= 0);
const uint32 kBytesPerRowUnknown = 0;
size_t bytesPerPixel;
size_t rowAlignment;
if (get_pixel_size_for(colorSpace, &bytesPerPixel, &rowAlignment, NULL) != B_OK)
return kBytesPerRowUnknown;
uint32 bytesPerRow = bytesPerPixel * videoWidth;
uint32 numberOfUnalignedBytes = bytesPerRow % rowAlignment;
if (numberOfUnalignedBytes == 0)
return bytesPerRow;
uint32 numberOfBytesNeededForAlignment = rowAlignment - numberOfUnalignedBytes;
bytesPerRow += numberOfBytesNeededForAlignment;
return bytesPerRow;
}
#endif // UTILITIES_H