Commit 3b7fe737 authored by changbin.shao's avatar changbin.shao Committed by Commit bot

Add support for color formats negotiation.

The color format parameter is hard coded for AndroidVideoEncodeAccelerator, we'd
better add negotiation with the codec for supported color formats.

BUG=423602

Review URL: https://codereview.chromium.org/648613003

Cr-Commit-Position: refs/heads/master@{#300651}
parent 418313cf
......@@ -4,6 +4,8 @@
#include "content/common/gpu/media/android_video_encode_accelerator.h"
#include <set>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
......@@ -26,8 +28,9 @@ using media::VideoFrame;
namespace content {
enum {
enum PixelFormat {
// Subset of MediaCodecInfo.CodecCapabilities.
COLOR_FORMAT_YUV420_PLANAR = 19,
COLOR_FORMAT_YUV420_SEMIPLANAR = 21,
};
......@@ -67,6 +70,19 @@ static inline const base::TimeDelta NoWaitTimeOut() {
return base::TimeDelta::FromMicroseconds(0);
}
static bool GetSupportedColorFormatForMime(const std::string& mime,
PixelFormat* pixel_format) {
std::set<int> formats = MediaCodecBridge::GetEncoderColorFormats(mime);
if (formats.count(COLOR_FORMAT_YUV420_SEMIPLANAR) > 0)
*pixel_format = COLOR_FORMAT_YUV420_SEMIPLANAR;
else if (formats.count(COLOR_FORMAT_YUV420_PLANAR) > 0)
*pixel_format = COLOR_FORMAT_YUV420_PLANAR;
else
return false;
return true;
}
AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator()
: num_buffers_at_codec_(0),
num_output_buffers_(-1),
......@@ -142,17 +158,17 @@ bool AndroidVideoEncodeAccelerator::Initialize(
return false;
}
// TODO(fischman): when there is more HW out there with different color-space
// support, this should turn into a negotiation with the codec for supported
// formats. For now we use the only format supported by the only available
// HW.
media_codec_.reset(
media::VideoCodecBridge::CreateEncoder(media::kCodecVP8,
input_visible_size,
initial_bitrate,
INITIAL_FRAMERATE,
IFRAME_INTERVAL,
COLOR_FORMAT_YUV420_SEMIPLANAR));
PixelFormat pixel_format = COLOR_FORMAT_YUV420_SEMIPLANAR;
if (!GetSupportedColorFormatForMime("video/x-vnd.on2.vp8", &pixel_format)) {
DLOG(ERROR) << "No color format support.";
return false;
}
media_codec_.reset(media::VideoCodecBridge::CreateEncoder(media::kCodecVP8,
input_visible_size,
initial_bitrate,
INITIAL_FRAMERATE,
IFRAME_INTERVAL,
pixel_format));
if (!media_codec_) {
DLOG(ERROR) << "Failed to create/start the codec: "
......
......@@ -228,6 +228,30 @@ class MediaCodecBridge {
return codecName;
}
/**
* Get a list of encoder supported color formats for specified mime type.
*/
@CalledByNative
private static int[] getEncoderColorFormatsForMime(String mime) {
int count = MediaCodecList.getCodecCount();
for (int i = 0; i < count; ++i) {
MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
if (!info.isEncoder())
continue;
String[] supportedTypes = info.getSupportedTypes();
for (int j = 0; j < supportedTypes.length; ++j) {
if (!supportedTypes[j].equalsIgnoreCase(mime))
continue;
MediaCodecInfo.CodecCapabilities capabilities =
info.getCapabilitiesForType(mime);
return capabilities.colorFormats;
}
}
return null;
}
@SuppressWarnings("deprecation")
private static String getDecoderNameForMime(String mime) {
int count = MediaCodecList.getCodecCount();
......
......@@ -24,6 +24,7 @@
using base::android::AttachCurrentThread;
using base::android::ConvertJavaStringToUTF8;
using base::android::ConvertUTF8ToJavaString;
using base::android::JavaIntArrayToIntVector;
using base::android::ScopedJavaLocalRef;
namespace media {
......@@ -170,6 +171,27 @@ std::string MediaCodecBridge::GetDefaultCodecName(
return ConvertJavaStringToUTF8(env, j_codec_name.obj());
}
// static
std::set<int> MediaCodecBridge::GetEncoderColorFormats(
const std::string& mime_type) {
std::set<int> color_formats;
if (!IsAvailable())
return color_formats;
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type);
ScopedJavaLocalRef<jintArray> j_color_format_array =
Java_MediaCodecBridge_getEncoderColorFormatsForMime(env, j_mime.obj());
if (j_color_format_array.obj()) {
std::vector<int> formats;
JavaIntArrayToIntVector(env, j_color_format_array.obj(), &formats);
color_formats = std::set<int>(formats.begin(), formats.end());
}
return color_formats;
}
// static
bool MediaCodecBridge::CanDecode(const std::string& codec, bool is_secure) {
if (!IsAvailable())
......
......@@ -81,6 +81,11 @@ class MEDIA_EXPORT MediaCodecBridge {
static std::string GetDefaultCodecName(const std::string& mime_type,
MediaCodecDirection direction);
// Get a list of encoder supported color formats for |mime_type|.
// The mapping of color format name and its value refers to
// MediaCodecInfo.CodecCapabilities.
static std::set<int> GetEncoderColorFormats(const std::string& mime_type);
virtual ~MediaCodecBridge();
// Resets both input and output, all indices previously returned in calls to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment