Chromium Code Reviews| Index: media/cast/sender/h264_vt_encoder.cc |
| diff --git a/media/cast/sender/h264_vt_encoder.cc b/media/cast/sender/h264_vt_encoder.cc |
| index 33923488c51daa96b99847893ea713204588837c..8aa1623f4c5e23e5613c2fc36771f16aa44b9093 100644 |
| --- a/media/cast/sender/h264_vt_encoder.cc |
| +++ b/media/cast/sender/h264_vt_encoder.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/bind_helpers.h" |
| #include "base/location.h" |
| #include "base/logging.h" |
| +#include "base/macros.h" |
| #include "media/base/mac/corevideo_glue.h" |
| #include "media/base/mac/video_frame_mac.h" |
| #include "media/cast/sender/video_frame_factory.h" |
| @@ -43,6 +44,21 @@ base::ScopedCFTypeRef<CFDictionaryRef> DictionaryWithKeyValue(CFTypeRef key, |
| &kCFTypeDictionaryValueCallBacks)); |
| } |
| +base::ScopedCFTypeRef<CFArrayRef> ArrayWithIntegers(const std::vector<int>& v) { |
| + std::vector<CFNumberRef> numbers; |
| + numbers.reserve(v.size()); |
| + for (const int i : v) { |
| + numbers.push_back(CFNumberCreate(nullptr, kCFNumberSInt32Type, &i)); |
| + } |
| + base::ScopedCFTypeRef<CFArrayRef> array(CFArrayCreate( |
| + kCFAllocatorDefault, reinterpret_cast<const void**>(&numbers[0]), |
| + numbers.size(), &kCFTypeArrayCallBacks)); |
| + for (CFNumberRef number : numbers) { |
| + CFRelease(number); |
| + } |
| + return array; |
| +} |
| + |
| template <typename NalSizeType> |
| void CopyNalsToAnnexB(char* avcc_buffer, |
| const size_t avcc_size, |
| @@ -257,11 +273,20 @@ bool H264VideoToolboxEncoder::Initialize( |
| kCFBooleanTrue); |
| #endif |
| + // Certain encoders prefer kCVPixelFormatType_422YpCbCr8, which is not |
| + // supported through VideoFrame. We can force 420 formats to be used instead. |
| + const int formats[] = { |
|
miu
2015/01/22 00:01:22
Wow. This is all a bit heavy-weight to pass in an
|
| + kCVPixelFormatType_420YpCbCr8Planar, |
| + CoreVideoGlue::kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange}; |
| + base::ScopedCFTypeRef<CFArrayRef> formats_array = ArrayWithIntegers( |
| + std::vector<int>(formats, formats + arraysize(formats))); |
| + base::ScopedCFTypeRef<CFDictionaryRef> buffer_attributes = |
| + DictionaryWithKeyValue(kCVPixelBufferPixelFormatTypeKey, formats_array); |
| + |
| VTCompressionSessionRef session; |
| OSStatus status = videotoolbox_glue_->VTCompressionSessionCreate( |
| kCFAllocatorDefault, video_config.width, video_config.height, |
| - CoreMediaGlue::kCMVideoCodecType_H264, encoder_spec, |
| - nullptr /* sourceImageBufferAttributes */, |
| + CoreMediaGlue::kCMVideoCodecType_H264, encoder_spec, buffer_attributes, |
| nullptr /* compressedDataAllocator */, |
| &H264VideoToolboxEncoder::CompressionCallback, |
| reinterpret_cast<void*>(this), &session); |