Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(670)

Unified Diff: media/cast/sender/h264_vt_encoder.cc

Issue 859303004: [cast] Force 4:2:0 pixel formats in H264VideoToolboxEncoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5e253ed26b968d67c1e9a44b34e30d731632f384 100644
--- a/media/cast/sender/h264_vt_encoder.cc
+++ b/media/cast/sender/h264_vt_encoder.cc
@@ -5,12 +5,14 @@
#include "media/cast/sender/h264_vt_encoder.h"
#include <string>
+#include <vector>
#include "base/big_endian.h"
#include "base/bind.h"
#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 +45,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 +274,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[] = {
+ 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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698