summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhajimehoshi <hajimehoshi@chromium.org>2015-10-19 01:04:35 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-19 08:05:22 +0000
commit3d5d4e33ef71fecdafaaa920ad5a1b4fe03d13fb (patch)
tree0270e4cd1f2d6f686cb548f1e14c8c7354337e3f
parent8cfd9626b3e4ad0fa3822d3ca9da5791d6804247 (diff)
downloadchromium_src-3d5d4e33ef71fecdafaaa920ad5a1b4fe03d13fb.zip
chromium_src-3d5d4e33ef71fecdafaaa920ad5a1b4fe03d13fb.tar.gz
chromium_src-3d5d4e33ef71fecdafaaa920ad5a1b4fe03d13fb.tar.bz2
Revert of Fail playback when VideoDecoderConfig has invalid extra data. (patchset #14 id:260001 of https://codereview.chromium.org/1396583002/ )
Reason for revert: This causes a compile error on Mac (crbug.com/544748). Original issue's description: > Fail playback when VideoDecoderConfig has invalid extra data. > > Invalid extra data occurs when: > (extra_data_ptr == NULL) != (extra_data_size == 0) > > We were previously crashing (CHECK) on this condition. > {Audio|Video}DecoderConfig now use a vector and pointer/size issues > are detected/handled in the path of creating the FFmpegDemuxerStream. > > BUG=517163 > TEST=New unit test. Manually verified graceful failure for MSE & SRC= > R=bbudge@chromium.org, gunsch@chromium.org, sandersd@chromium.org, xhwang@chromium.org > > Committed: https://chromium.googlesource.com/chromium/src/+/54d0dc5450e6d8d6a7cd80bd9fa512a41999e08e TBR=xhwang@chromium.org,bbudge@chromium.org,lcwu@chromium.org,gunsch@chromium.org,sandersd@chromium.org,chcunningham@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=517163 Review URL: https://codereview.chromium.org/1409353003 Cr-Commit-Position: refs/heads/master@{#354735}
-rw-r--r--chromecast/common/media/cma_param_traits.cc29
-rw-r--r--chromecast/media/audio/cast_audio_output_stream.cc2
-rw-r--r--chromecast/media/cma/base/decoder_config_adapter.cc17
-rw-r--r--chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.cc18
-rw-r--r--chromecast/media/cma/ipc_streamer/video_decoder_config_marshaller.cc18
-rw-r--r--chromecast/media/cma/pipeline/audio_video_pipeline_impl_unittest.cc7
-rw-r--r--chromecast/media/cma/test/mock_frame_provider.cc6
-rw-r--r--chromecast/renderer/media/demuxer_stream_for_test.cc7
-rw-r--r--content/common/gpu/media/video_encode_accelerator_unittest.cc5
-rw-r--r--content/renderer/media/android/media_source_delegate.cc6
-rw-r--r--content/renderer/pepper/content_decryptor_delegate.cc16
-rw-r--r--content/renderer/pepper/video_decoder_shim.cc5
-rw-r--r--media/base/BUILD.gn2
-rw-r--r--media/base/audio_decoder_config.cc18
-rw-r--r--media/base/audio_decoder_config.h23
-rw-r--r--media/base/fake_demuxer_stream.cc6
-rw-r--r--media/base/media_util.cc13
-rw-r--r--media/base/media_util.h21
-rw-r--r--media/base/test_helpers.cc5
-rw-r--r--media/base/video_decoder_config.cc30
-rw-r--r--media/base/video_decoder_config.h11
-rw-r--r--media/ffmpeg/ffmpeg_common.cc93
-rw-r--r--media/ffmpeg/ffmpeg_common.h17
-rw-r--r--media/ffmpeg/ffmpeg_common_unittest.cc102
-rw-r--r--media/filters/audio_decoder_selector_unittest.cc9
-rw-r--r--media/filters/audio_decoder_unittest.cc21
-rw-r--r--media/filters/chunk_demuxer_unittest.cc14
-rw-r--r--media/filters/decrypting_audio_decoder_unittest.cc19
-rw-r--r--media/filters/decrypting_demuxer_stream.cc2
-rw-r--r--media/filters/decrypting_demuxer_stream_unittest.cc35
-rw-r--r--media/filters/ffmpeg_demuxer.cc114
-rw-r--r--media/filters/ffmpeg_demuxer.h25
-rw-r--r--media/filters/ffmpeg_demuxer_unittest.cc6
-rw-r--r--media/filters/ffmpeg_glue.cc2
-rw-r--r--media/filters/ffmpeg_video_decoder_unittest.cc29
-rw-r--r--media/filters/frame_processor_unittest.cc12
-rw-r--r--media/filters/opus_audio_decoder.cc4
-rw-r--r--media/filters/source_buffer_stream_unittest.cc19
-rw-r--r--media/formats/mp2t/es_adapter_video_unittest.cc3
-rw-r--r--media/formats/mp2t/es_parser_adts.cc10
-rw-r--r--media/formats/mp2t/es_parser_h264.cc4
-rw-r--r--media/formats/mp2t/es_parser_mpeg1audio.cc4
-rw-r--r--media/formats/mp4/mp4_stream_parser.cc21
-rw-r--r--media/formats/mpeg/mpeg_audio_stream_parser_base.cc3
-rw-r--r--media/formats/webm/webm_audio_client.cc10
-rw-r--r--media/formats/webm/webm_video_client.cc10
-rw-r--r--media/media.gyp2
-rw-r--r--media/mojo/services/media_type_converters.cc23
-rw-r--r--media/mojo/services/media_type_converters_unittest.cc16
-rw-r--r--media/renderers/audio_renderer_impl_unittest.cc4
50 files changed, 356 insertions, 542 deletions
diff --git a/chromecast/common/media/cma_param_traits.cc b/chromecast/common/media/cma_param_traits.cc
index 2ae4fd9..ab0f62a 100644
--- a/chromecast/common/media/cma_param_traits.cc
+++ b/chromecast/common/media/cma_param_traits.cc
@@ -34,7 +34,13 @@ void ParamTraits<media::AudioDecoderConfig>::Write(
WriteParam(m, p.channel_layout());
WriteParam(m, p.samples_per_second());
WriteParam(m, p.is_encrypted());
- WriteParam(m, p.extra_data());
+ std::vector<uint8> extra_data;
+ if (p.extra_data_size() > 0) {
+ extra_data =
+ std::vector<uint8>(p.extra_data(),
+ p.extra_data() + p.extra_data_size());
+ }
+ WriteParam(m, extra_data);
}
bool ParamTraits<media::AudioDecoderConfig>::Read(
@@ -52,8 +58,13 @@ bool ParamTraits<media::AudioDecoderConfig>::Read(
!ReadParam(m, iter, &samples_per_second) ||
!ReadParam(m, iter, &is_encrypted) || !ReadParam(m, iter, &extra_data))
return false;
+ const uint8* extra_data_ptr = nullptr;
+ if (!extra_data.empty())
+ extra_data_ptr = &extra_data[0];
*r = media::AudioDecoderConfig(codec, sample_format, channel_layout,
- samples_per_second, extra_data, is_encrypted);
+ samples_per_second,
+ extra_data_ptr, extra_data.size(),
+ is_encrypted);
return true;
}
@@ -72,7 +83,13 @@ void ParamTraits<media::VideoDecoderConfig>::Write(
WriteParam(m, p.visible_rect());
WriteParam(m, p.natural_size());
WriteParam(m, p.is_encrypted());
- WriteParam(m, p.extra_data());
+ std::vector<uint8> extra_data;
+ if (p.extra_data_size() > 0) {
+ extra_data =
+ std::vector<uint8>(p.extra_data(),
+ p.extra_data() + p.extra_data_size());
+ }
+ WriteParam(m, extra_data);
}
bool ParamTraits<media::VideoDecoderConfig>::Read(
@@ -94,9 +111,13 @@ bool ParamTraits<media::VideoDecoderConfig>::Read(
!ReadParam(m, iter, &natural_size) ||
!ReadParam(m, iter, &is_encrypted) || !ReadParam(m, iter, &extra_data))
return false;
+ const uint8* extra_data_ptr = nullptr;
+ if (!extra_data.empty())
+ extra_data_ptr = &extra_data[0];
*r = media::VideoDecoderConfig(codec, profile, format, color_space,
coded_size, visible_rect, natural_size,
- extra_data, is_encrypted);
+ extra_data_ptr, extra_data.size(),
+ is_encrypted);
return true;
}
diff --git a/chromecast/media/audio/cast_audio_output_stream.cc b/chromecast/media/audio/cast_audio_output_stream.cc
index 69eda32..e55f127 100644
--- a/chromecast/media/audio/cast_audio_output_stream.cc
+++ b/chromecast/media/audio/cast_audio_output_stream.cc
@@ -42,6 +42,8 @@ MediaPipelineBackend::AudioDecoder* InitializeBackend(
audio_config.bytes_per_channel = audio_params.bits_per_sample() / 8;
audio_config.channel_number = audio_params.channels();
audio_config.samples_per_second = audio_params.sample_rate();
+ audio_config.extra_data = nullptr;
+ audio_config.extra_data_size = 0;
audio_config.is_encrypted = false;
if (!decoder->SetConfig(audio_config))
diff --git a/chromecast/media/cma/base/decoder_config_adapter.cc b/chromecast/media/cma/base/decoder_config_adapter.cc
index 248edd0..b75d5f2 100644
--- a/chromecast/media/cma/base/decoder_config_adapter.cc
+++ b/chromecast/media/cma/base/decoder_config_adapter.cc
@@ -182,8 +182,8 @@ AudioConfig DecoderConfigAdapter::ToCastAudioConfig(
::media::ChannelLayoutToChannelCount(config.channel_layout()),
audio_config.samples_per_second = config.samples_per_second();
audio_config.extra_data =
- (config.extra_data().empty()) ? nullptr : &config.extra_data()[0];
- audio_config.extra_data_size = config.extra_data().size();
+ (config.extra_data_size() > 0) ? config.extra_data() : nullptr;
+ audio_config.extra_data_size = config.extra_data_size();
audio_config.is_encrypted = config.is_encrypted();
return audio_config;
}
@@ -191,16 +191,11 @@ AudioConfig DecoderConfigAdapter::ToCastAudioConfig(
// static
::media::AudioDecoderConfig DecoderConfigAdapter::ToMediaAudioDecoderConfig(
const AudioConfig& config) {
- std::vector<uint8_t> extra_data;
- if (config.extra_data_size > 0)
- extra_data.assign(config.extra_data,
- config.extra_data + config.extra_data_size);
-
return ::media::AudioDecoderConfig(
ToMediaAudioCodec(config.codec),
ToMediaSampleFormat(config.sample_format),
ToMediaChannelLayout(config.channel_number), config.samples_per_second,
- extra_data, config.is_encrypted);
+ config.extra_data, config.extra_data_size, config.is_encrypted);
}
// static
@@ -215,9 +210,9 @@ VideoConfig DecoderConfigAdapter::ToCastVideoConfig(
video_config.id = id;
video_config.codec = ToVideoCodec(config.codec());
video_config.profile = ToVideoProfile(config.profile());
- video_config.extra_data = (config.extra_data().empty()) ?
- nullptr : &config.extra_data()[0];
- video_config.extra_data_size = config.extra_data().size();
+ video_config.extra_data = (config.extra_data_size() > 0) ?
+ config.extra_data() : nullptr;
+ video_config.extra_data_size = config.extra_data_size();
video_config.is_encrypted = config.is_encrypted();
return video_config;
}
diff --git a/chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.cc b/chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.cc
index 2bc40f4..d595bda 100644
--- a/chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.cc
+++ b/chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.cc
@@ -4,8 +4,6 @@
#include "chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.h"
-#include <vector>
-
#include "base/basictypes.h"
#include "base/logging.h"
#include "chromecast/media/cma/ipc/media_message.h"
@@ -26,10 +24,9 @@ void AudioDecoderConfigMarshaller::Write(
CHECK(msg->WritePod(config.samples_per_second()));
CHECK(msg->WritePod(config.sample_format()));
CHECK(msg->WritePod(config.is_encrypted()));
- CHECK(msg->WritePod(config.extra_data().size()));
- if (!config.extra_data().empty())
- CHECK(msg->WriteBuffer(&config.extra_data()[0],
- config.extra_data().size()));
+ CHECK(msg->WritePod(config.extra_data_size()));
+ if (config.extra_data_size() > 0)
+ CHECK(msg->WriteBuffer(config.extra_data(), config.extra_data_size()));
}
// static
@@ -41,7 +38,7 @@ void AudioDecoderConfigMarshaller::Write(
int samples_per_second;
bool is_encrypted;
size_t extra_data_size;
- std::vector<uint8_t> extra_data;
+ scoped_ptr<uint8[]> extra_data;
CHECK(msg->ReadPod(&codec));
CHECK(msg->ReadPod(&channel_layout));
@@ -58,14 +55,15 @@ void AudioDecoderConfigMarshaller::Write(
CHECK_LE(sample_format, ::media::kSampleFormatMax);
CHECK_LT(extra_data_size, kMaxExtraDataSize);
if (extra_data_size > 0) {
- extra_data.resize(extra_data_size);
- CHECK(msg->ReadBuffer(&extra_data[0], extra_data.size()));
+ extra_data.reset(new uint8[extra_data_size]);
+ CHECK(msg->ReadBuffer(extra_data.get(), extra_data_size));
}
return ::media::AudioDecoderConfig(
codec, sample_format,
channel_layout, samples_per_second,
- extra_data, is_encrypted);
+ extra_data.get(), extra_data_size,
+ is_encrypted);
}
} // namespace media
diff --git a/chromecast/media/cma/ipc_streamer/video_decoder_config_marshaller.cc b/chromecast/media/cma/ipc_streamer/video_decoder_config_marshaller.cc
index 8cd28ae..1c07352 100644
--- a/chromecast/media/cma/ipc_streamer/video_decoder_config_marshaller.cc
+++ b/chromecast/media/cma/ipc_streamer/video_decoder_config_marshaller.cc
@@ -4,8 +4,6 @@
#include "chromecast/media/cma/ipc_streamer/video_decoder_config_marshaller.h"
-#include <vector>
-
#include "base/basictypes.h"
#include "base/logging.h"
#include "chromecast/media/cma/ipc/media_message.h"
@@ -66,10 +64,9 @@ void VideoDecoderConfigMarshaller::Write(
RectMarshaller::Write(config.visible_rect(), msg);
SizeMarshaller::Write(config.natural_size(), msg);
CHECK(msg->WritePod(config.is_encrypted()));
- CHECK(msg->WritePod(config.extra_data().size()));
- if (!config.extra_data().empty())
- CHECK(msg->WriteBuffer(&config.extra_data()[0],
- config.extra_data().size()));
+ CHECK(msg->WritePod(config.extra_data_size()));
+ if (config.extra_data_size() > 0)
+ CHECK(msg->WriteBuffer(config.extra_data(), config.extra_data_size()));
}
// static
@@ -84,7 +81,7 @@ void VideoDecoderConfigMarshaller::Write(
gfx::Size natural_size;
bool is_encrypted;
size_t extra_data_size;
- std::vector<uint8_t> extra_data;
+ scoped_ptr<uint8[]> extra_data;
CHECK(msg->ReadPod(&codec));
CHECK(msg->ReadPod(&profile));
@@ -106,14 +103,15 @@ void VideoDecoderConfigMarshaller::Write(
CHECK_LE(color_space, ::media::COLOR_SPACE_MAX);
CHECK_LT(extra_data_size, kMaxExtraDataSize);
if (extra_data_size > 0) {
- extra_data.resize(extra_data_size);
- CHECK(msg->ReadBuffer(&extra_data[0], extra_data.size()));
+ extra_data.reset(new uint8[extra_data_size]);
+ CHECK(msg->ReadBuffer(extra_data.get(), extra_data_size));
}
return ::media::VideoDecoderConfig(
codec, profile, format, color_space,
coded_size, visible_rect, natural_size,
- extra_data, is_encrypted);
+ extra_data.get(), extra_data_size,
+ is_encrypted);
}
} // namespace media
diff --git a/chromecast/media/cma/pipeline/audio_video_pipeline_impl_unittest.cc b/chromecast/media/cma/pipeline/audio_video_pipeline_impl_unittest.cc
index 981247c..040f96e 100644
--- a/chromecast/media/cma/pipeline/audio_video_pipeline_impl_unittest.cc
+++ b/chromecast/media/cma/pipeline/audio_video_pipeline_impl_unittest.cc
@@ -25,7 +25,6 @@
#include "chromecast/media/cma/test/mock_frame_provider.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/decoder_buffer.h"
-#include "media/base/media_util.h"
#include "media/base/video_decoder_config.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -81,13 +80,13 @@ void AudioVideoPipelineImplTest::Initialize(
::media::kSampleFormatS16,
::media::CHANNEL_LAYOUT_STEREO,
44100,
- ::media::EmptyExtraData(), false);
+ NULL, 0, false);
std::vector<::media::VideoDecoderConfig> video_configs;
video_configs.push_back(::media::VideoDecoderConfig(
::media::kCodecH264, ::media::H264PROFILE_MAIN,
::media::PIXEL_FORMAT_I420, ::media::COLOR_SPACE_UNSPECIFIED,
- gfx::Size(640, 480), gfx::Rect(0, 0, 640, 480), gfx::Size(640, 480),
- ::media::EmptyExtraData(), false));
+ gfx::Size(640, 480), gfx::Rect(0, 0, 640, 480), gfx::Size(640, 480), NULL,
+ 0, false));
// Frame generation on the producer side.
std::vector<FrameGeneratorForTest::FrameSpec> frame_specs;
diff --git a/chromecast/media/cma/test/mock_frame_provider.cc b/chromecast/media/cma/test/mock_frame_provider.cc
index fdab889..27649a7 100644
--- a/chromecast/media/cma/test/mock_frame_provider.cc
+++ b/chromecast/media/cma/test/mock_frame_provider.cc
@@ -13,7 +13,6 @@
#include "chromecast/media/cma/test/frame_generator_for_test.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/decoder_buffer.h"
-#include "media/base/media_util.h"
#include "media/base/video_decoder_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
@@ -81,15 +80,14 @@ void MockFrameProvider::DoRead(const ReadCB& read_cb) {
video_config = ::media::VideoDecoderConfig(
::media::kCodecH264, ::media::VIDEO_CODEC_PROFILE_UNKNOWN,
::media::PIXEL_FORMAT_YV12, ::media::COLOR_SPACE_UNSPECIFIED,
- coded_size, visible_rect, natural_size, ::media::EmptyExtraData(),
- false);
+ coded_size, visible_rect, natural_size, NULL, 0, false);
audio_config = ::media::AudioDecoderConfig(
::media::kCodecAAC,
::media::kSampleFormatS16,
::media::CHANNEL_LAYOUT_STEREO,
44100,
- ::media::EmptyExtraData(),
+ NULL, 0,
false);
}
diff --git a/chromecast/renderer/media/demuxer_stream_for_test.cc b/chromecast/renderer/media/demuxer_stream_for_test.cc
index 89b45ea..228f1de 100644
--- a/chromecast/renderer/media/demuxer_stream_for_test.cc
+++ b/chromecast/renderer/media/demuxer_stream_for_test.cc
@@ -2,10 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chromecast/renderer/media/demuxer_stream_for_test.h"
-
#include "base/threading/thread.h"
-#include "media/base/media_util.h"
+#include "chromecast/renderer/media/demuxer_stream_for_test.h"
namespace chromecast {
namespace media {
@@ -62,7 +60,8 @@ void DemuxerStreamForTest::Read(const ReadCB& read_cb) {
coded_size,
visible_rect,
natural_size,
- ::media::EmptyExtraData(),
+ NULL,
+ 0,
false);
}
diff --git a/content/common/gpu/media/video_encode_accelerator_unittest.cc b/content/common/gpu/media/video_encode_accelerator_unittest.cc
index e22bd42..b612bd8 100644
--- a/content/common/gpu/media/video_encode_accelerator_unittest.cc
+++ b/content/common/gpu/media/video_encode_accelerator_unittest.cc
@@ -28,7 +28,6 @@
#include "media/base/bind_to_current_loop.h"
#include "media/base/bitstream_buffer.h"
#include "media/base/decoder_buffer.h"
-#include "media/base/media_util.h"
#include "media/base/test_data_util.h"
#include "media/base/video_decoder.h"
#include "media/base/video_frame.h"
@@ -660,11 +659,11 @@ void VideoFrameQualityValidator::Initialize(const gfx::Size& coded_size,
if (IsVP8(profile_))
config.Initialize(media::kCodecVP8, media::VP8PROFILE_ANY, kInputFormat,
media::COLOR_SPACE_UNSPECIFIED, coded_size, visible_size,
- natural_size, media::EmptyExtraData(), false);
+ natural_size, NULL, 0, false);
else if (IsH264(profile_))
config.Initialize(media::kCodecH264, media::H264PROFILE_MAIN, kInputFormat,
media::COLOR_SPACE_UNSPECIFIED, coded_size, visible_size,
- natural_size, media::EmptyExtraData(), false);
+ natural_size, NULL, 0, false);
else
LOG_ASSERT(0) << "Invalid profile " << profile_;
diff --git a/content/renderer/media/android/media_source_delegate.cc b/content/renderer/media/android/media_source_delegate.cc
index 4c0477b..139be4a 100644
--- a/content/renderer/media/android/media_source_delegate.cc
+++ b/content/renderer/media/android/media_source_delegate.cc
@@ -736,7 +736,8 @@ bool MediaSourceDelegate::GetDemuxerConfigFromStream(
media::ChannelLayoutToChannelCount(config.channel_layout());
configs->audio_sampling_rate = config.samples_per_second();
configs->is_audio_encrypted = config.is_encrypted();
- configs->audio_extra_data = config.extra_data();
+ configs->audio_extra_data = std::vector<uint8>(
+ config.extra_data(), config.extra_data() + config.extra_data_size());
configs->audio_codec_delay_ns = static_cast<int64_t>(
config.codec_delay() *
(static_cast<double>(base::Time::kNanosecondsPerSecond) /
@@ -751,7 +752,8 @@ bool MediaSourceDelegate::GetDemuxerConfigFromStream(
configs->video_codec = config.codec();
configs->video_size = config.natural_size();
configs->is_video_encrypted = config.is_encrypted();
- configs->video_extra_data = config.extra_data();
+ configs->video_extra_data = std::vector<uint8>(
+ config.extra_data(), config.extra_data() + config.extra_data_size());
return true;
}
return false;
diff --git a/content/renderer/pepper/content_decryptor_delegate.cc b/content/renderer/pepper/content_decryptor_delegate.cc
index 2efb849..a3596c8 100644
--- a/content/renderer/pepper/content_decryptor_delegate.cc
+++ b/content/renderer/pepper/content_decryptor_delegate.cc
@@ -4,8 +4,6 @@
#include "content/renderer/pepper/content_decryptor_delegate.h"
-#include <vector>
-
#include "base/callback_helpers.h"
#include "base/metrics/sparse_histogram.h"
#include "base/numerics/safe_conversions.h"
@@ -55,25 +53,27 @@ namespace {
// reference-count of 0. If |data| is NULL, sets |*resource| to NULL. Returns
// true upon success and false if any error happened.
bool MakeBufferResource(PP_Instance instance,
- const std::vector<uint8_t>& data,
+ const uint8_t* data,
+ uint32_t size,
scoped_refptr<PPB_Buffer_Impl>* resource) {
TRACE_EVENT0("media", "ContentDecryptorDelegate - MakeBufferResource");
DCHECK(resource);
- if (data.empty()) {
+ if (!data || !size) {
+ DCHECK(!data && !size);
resource = NULL;
return true;
}
scoped_refptr<PPB_Buffer_Impl> buffer(
- PPB_Buffer_Impl::CreateResource(instance, data.size()));
+ PPB_Buffer_Impl::CreateResource(instance, size));
if (!buffer.get())
return false;
BufferAutoMapper mapper(buffer.get());
- if (!mapper.data() || mapper.size() < data.size())
+ if (!mapper.data() || mapper.size() < size)
return false;
- memcpy(mapper.data(), &data[0], data.size());
+ memcpy(mapper.data(), data, size);
*resource = buffer;
return true;
@@ -592,6 +592,7 @@ bool ContentDecryptorDelegate::InitializeAudioDecoder(
scoped_refptr<PPB_Buffer_Impl> extra_data_resource;
if (!MakeBufferResource(pp_instance_,
decoder_config.extra_data(),
+ decoder_config.extra_data_size(),
&extra_data_resource)) {
return false;
}
@@ -620,6 +621,7 @@ bool ContentDecryptorDelegate::InitializeVideoDecoder(
scoped_refptr<PPB_Buffer_Impl> extra_data_resource;
if (!MakeBufferResource(pp_instance_,
decoder_config.extra_data(),
+ decoder_config.extra_data_size(),
&extra_data_resource)) {
return false;
}
diff --git a/content/renderer/pepper/video_decoder_shim.cc b/content/renderer/pepper/video_decoder_shim.cc
index d3c3d1b..d84ac81 100644
--- a/content/renderer/pepper/video_decoder_shim.cc
+++ b/content/renderer/pepper/video_decoder_shim.cc
@@ -23,7 +23,6 @@
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "media/base/decoder_buffer.h"
#include "media/base/limits.h"
-#include "media/base/media_util.h"
#include "media/base/video_decoder.h"
#include "media/blink/skcanvas_video_renderer.h"
#include "media/filters/ffmpeg_video_decoder.h"
@@ -883,8 +882,8 @@ bool VideoDecoderShim::Initialize(
codec, profile, media::PIXEL_FORMAT_YV12, media::COLOR_SPACE_UNSPECIFIED,
gfx::Size(32, 24), // Small sizes that won't fail.
gfx::Rect(32, 24), gfx::Size(32, 24),
- // TODO(bbudge): Verify extra data isn't needed.
- media::EmptyExtraData(), false /* decryption */);
+ NULL /* extra_data */, // TODO(bbudge) Verify this isn't needed.
+ 0 /* extra_data_size */, false /* decryption */);
media_task_runner_->PostTask(
FROM_HERE,
diff --git a/media/base/BUILD.gn b/media/base/BUILD.gn
index 8ca0edf..691e130 100644
--- a/media/base/BUILD.gn
+++ b/media/base/BUILD.gn
@@ -122,8 +122,6 @@ source_set("base") {
"media_resources.h",
"media_switches.cc",
"media_switches.h",
- "media_util.cc",
- "media_util.h",
"mime_util.cc",
"mime_util.h",
"moving_average.cc",
diff --git a/media/base/audio_decoder_config.cc b/media/base/audio_decoder_config.cc
index 213cb10..6dc5b2f 100644
--- a/media/base/audio_decoder_config.cc
+++ b/media/base/audio_decoder_config.cc
@@ -24,26 +24,30 @@ AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec,
SampleFormat sample_format,
ChannelLayout channel_layout,
int samples_per_second,
- const std::vector<uint8_t>& extra_data,
+ const uint8* extra_data,
+ size_t extra_data_size,
bool is_encrypted) {
Initialize(codec, sample_format, channel_layout, samples_per_second,
- extra_data, is_encrypted, base::TimeDelta(), 0);
+ extra_data, extra_data_size, is_encrypted, base::TimeDelta(), 0);
}
void AudioDecoderConfig::Initialize(AudioCodec codec,
SampleFormat sample_format,
ChannelLayout channel_layout,
int samples_per_second,
- const std::vector<uint8_t>& extra_data,
+ const uint8* extra_data,
+ size_t extra_data_size,
bool is_encrypted,
base::TimeDelta seek_preroll,
int codec_delay) {
+ CHECK((extra_data_size != 0) == (extra_data != NULL));
+
codec_ = codec;
channel_layout_ = channel_layout;
samples_per_second_ = samples_per_second;
sample_format_ = sample_format;
bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format);
- extra_data_ = extra_data;
+ extra_data_.assign(extra_data, extra_data + extra_data_size);
is_encrypted_ = is_encrypted;
seek_preroll_ = seek_preroll;
codec_delay_ = codec_delay;
@@ -71,7 +75,9 @@ bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const {
(bytes_per_channel() == config.bytes_per_channel()) &&
(channel_layout() == config.channel_layout()) &&
(samples_per_second() == config.samples_per_second()) &&
- (extra_data() == config.extra_data()) &&
+ (extra_data_size() == config.extra_data_size()) &&
+ (!extra_data() || !memcmp(extra_data(), config.extra_data(),
+ extra_data_size())) &&
(is_encrypted() == config.is_encrypted()) &&
(sample_format() == config.sample_format()) &&
(seek_preroll() == config.seek_preroll()) &&
@@ -88,7 +94,7 @@ std::string AudioDecoderConfig::AsHumanReadableString() const {
<< " bytes_per_frame: " << bytes_per_frame()
<< " seek_preroll: " << seek_preroll().InMilliseconds() << "ms"
<< " codec_delay: " << codec_delay()
- << " has extra data? " << (extra_data().empty() ? "false" : "true")
+ << " has extra data? " << (extra_data() ? "true" : "false")
<< " encrypted? " << (is_encrypted() ? "true" : "false");
return s.str();
}
diff --git a/media/base/audio_decoder_config.h b/media/base/audio_decoder_config.h
index ae72383..c9c8593 100644
--- a/media/base/audio_decoder_config.h
+++ b/media/base/audio_decoder_config.h
@@ -55,22 +55,22 @@ class MEDIA_EXPORT AudioDecoderConfig {
// appropriate values before using.
AudioDecoderConfig();
- // Constructs an initialized object.
- AudioDecoderConfig(AudioCodec codec,
- SampleFormat sample_format,
- ChannelLayout channel_layout,
- int samples_per_second,
- const std::vector<uint8_t>& extra_data,
+ // Constructs an initialized object. It is acceptable to pass in NULL for
+ // |extra_data|, otherwise the memory is copied.
+ AudioDecoderConfig(AudioCodec codec, SampleFormat sample_format,
+ ChannelLayout channel_layout, int samples_per_second,
+ const uint8* extra_data, size_t extra_data_size,
bool is_encrypted);
~AudioDecoderConfig();
- // Resets the internal state of this object. |codec_delay| is in frames.
+ // Resets the internal state of this object. |codec_delay| is in frames.
void Initialize(AudioCodec codec,
SampleFormat sample_format,
ChannelLayout channel_layout,
int samples_per_second,
- const std::vector<uint8>& extra_data,
+ const uint8* extra_data,
+ size_t extra_data_size,
bool is_encrypted,
base::TimeDelta seek_preroll,
int codec_delay);
@@ -101,7 +101,10 @@ class MEDIA_EXPORT AudioDecoderConfig {
// Optional byte data required to initialize audio decoders such as Vorbis
// codebooks.
- const std::vector<uint8_t>& extra_data() const { return extra_data_; }
+ const uint8* extra_data() const {
+ return extra_data_.empty() ? NULL : &extra_data_[0];
+ }
+ size_t extra_data_size() const { return extra_data_.size(); }
// Whether the audio stream is potentially encrypted.
// Note that in a potentially encrypted audio stream, individual buffers
@@ -115,7 +118,7 @@ class MEDIA_EXPORT AudioDecoderConfig {
ChannelLayout channel_layout_;
int samples_per_second_;
int bytes_per_frame_;
- std::vector<uint8_t> extra_data_;
+ std::vector<uint8> extra_data_;
bool is_encrypted_;
// |seek_preroll_| is the duration of the data that the decoder must decode
diff --git a/media/base/fake_demuxer_stream.cc b/media/base/fake_demuxer_stream.cc
index fab0396..30ff406 100644
--- a/media/base/fake_demuxer_stream.cc
+++ b/media/base/fake_demuxer_stream.cc
@@ -4,8 +4,6 @@
#include "media/base/fake_demuxer_stream.h"
-#include <vector>
-
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/location.h"
@@ -14,7 +12,6 @@
#include "base/thread_task_runner_handle.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/decoder_buffer.h"
-#include "media/base/media_util.h"
#include "media/base/test_helpers.h"
#include "media/base/timestamp_constants.h"
#include "media/base/video_frame.h"
@@ -149,8 +146,7 @@ void FakeDemuxerStream::UpdateVideoDecoderConfig() {
video_decoder_config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN,
PIXEL_FORMAT_YV12, COLOR_SPACE_UNSPECIFIED,
next_coded_size_, kVisibleRect,
- next_coded_size_, EmptyExtraData(),
- is_encrypted_);
+ next_coded_size_, NULL, 0, is_encrypted_);
next_coded_size_.Enlarge(kWidthDelta, kHeightDelta);
}
diff --git a/media/base/media_util.cc b/media/base/media_util.cc
deleted file mode 100644
index bd7929f..0000000
--- a/media/base/media_util.cc
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "media/base/media_util.h"
-
-namespace media {
-
-std::vector<uint8_t> EmptyExtraData() {
- return std::vector<uint8_t>();
-}
-
-} // namespace media
diff --git a/media/base/media_util.h b/media/base/media_util.h
deleted file mode 100644
index 4e53c9a..0000000
--- a/media/base/media_util.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MEDIA_BASE_UTIL_H_
-#define MEDIA_BASE_UTIL_H_
-
-#include <stdint.h>
-#include <vector>
-
-#include "media/base/media_export.h"
-
-namespace media {
-
-// Simply returns an empty vector. {Audio|Video}DecoderConfig are often
-// constructed with empty extra data.
-MEDIA_EXPORT std::vector<uint8_t> EmptyExtraData();
-
-} // namespace media
-
-#endif // MEDIA_BASE_UTIL_H_
diff --git a/media/base/test_helpers.cc b/media/base/test_helpers.cc
index 84074bf..5da16ad 100644
--- a/media/base/test_helpers.cc
+++ b/media/base/test_helpers.cc
@@ -15,7 +15,6 @@
#include "media/base/audio_buffer.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/decoder_buffer.h"
-#include "media/base/media_util.h"
#include "ui/gfx/geometry/rect.h"
using ::testing::_;
@@ -128,8 +127,8 @@ static VideoDecoderConfig GetTestConfig(VideoCodec codec,
return VideoDecoderConfig(codec, VIDEO_CODEC_PROFILE_UNKNOWN,
PIXEL_FORMAT_YV12, COLOR_SPACE_UNSPECIFIED,
- coded_size, visible_rect, natural_size,
- EmptyExtraData(), is_encrypted);
+ coded_size, visible_rect, natural_size, NULL, 0,
+ is_encrypted);
}
static const gfx::Size kNormalSize(320, 240);
diff --git a/media/base/video_decoder_config.cc b/media/base/video_decoder_config.cc
index 84058e4..f867ad1 100644
--- a/media/base/video_decoder_config.cc
+++ b/media/base/video_decoder_config.cc
@@ -4,8 +4,6 @@
#include "media/base/video_decoder_config.h"
-#include <vector>
-
#include "base/logging.h"
#include "media/base/video_frame.h"
@@ -36,11 +34,13 @@ VideoCodec VideoCodecProfileToVideoCodec(VideoCodecProfile profile) {
return kUnknownVideoCodec;
}
+
VideoDecoderConfig::VideoDecoderConfig()
: codec_(kUnknownVideoCodec),
profile_(VIDEO_CODEC_PROFILE_UNKNOWN),
format_(PIXEL_FORMAT_UNKNOWN),
- is_encrypted_(false) {}
+ is_encrypted_(false) {
+}
VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec,
VideoCodecProfile profile,
@@ -49,10 +49,11 @@ VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec,
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
const gfx::Size& natural_size,
- const std::vector<uint8_t>& extra_data,
+ const uint8* extra_data,
+ size_t extra_data_size,
bool is_encrypted) {
Initialize(codec, profile, format, color_space, coded_size, visible_rect,
- natural_size, extra_data, is_encrypted);
+ natural_size, extra_data, extra_data_size, is_encrypted);
}
VideoDecoderConfig::~VideoDecoderConfig() {}
@@ -64,8 +65,11 @@ void VideoDecoderConfig::Initialize(VideoCodec codec,
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
const gfx::Size& natural_size,
- const std::vector<uint8_t>& extra_data,
+ const uint8* extra_data,
+ size_t extra_data_size,
bool is_encrypted) {
+ CHECK((extra_data_size != 0) == (extra_data != NULL));
+
codec_ = codec;
profile_ = profile;
format_ = format;
@@ -73,7 +77,7 @@ void VideoDecoderConfig::Initialize(VideoCodec codec,
coded_size_ = coded_size;
visible_rect_ = visible_rect;
natural_size_ = natural_size;
- extra_data_ = extra_data;
+ extra_data_.assign(extra_data, extra_data + extra_data_size);
is_encrypted_ = is_encrypted;
}
@@ -92,7 +96,9 @@ bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const {
(coded_size() == config.coded_size()) &&
(visible_rect() == config.visible_rect()) &&
(natural_size() == config.natural_size()) &&
- (extra_data() == config.extra_data()) &&
+ (extra_data_size() == config.extra_data_size()) &&
+ (!extra_data() || !memcmp(extra_data(), config.extra_data(),
+ extra_data_size())) &&
(is_encrypted() == config.is_encrypted()));
}
@@ -109,7 +115,7 @@ std::string VideoDecoderConfig::AsHumanReadableString() const {
<< "," << visible_rect().height() << "]"
<< " natural size: [" << natural_size().width()
<< "," << natural_size().height() << "]"
- << " has extra data? " << (extra_data().empty() ? "false" : "true")
+ << " has extra data? " << (extra_data() ? "true" : "false")
<< " encrypted? " << (is_encrypted() ? "true" : "false");
return s.str();
}
@@ -140,4 +146,10 @@ std::string VideoDecoderConfig::GetHumanReadableCodecName() const {
return "";
}
+const uint8* VideoDecoderConfig::extra_data() const {
+ if (extra_data_.empty())
+ return NULL;
+ return &extra_data_[0];
+}
+
} // namespace media
diff --git a/media/base/video_decoder_config.h b/media/base/video_decoder_config.h
index 3de0d2f..0dae77c8 100644
--- a/media/base/video_decoder_config.h
+++ b/media/base/video_decoder_config.h
@@ -35,7 +35,8 @@ class MEDIA_EXPORT VideoDecoderConfig {
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
const gfx::Size& natural_size,
- const std::vector<uint8_t>& extra_data,
+ const uint8* extra_data,
+ size_t extra_data_size,
bool is_encrypted);
~VideoDecoderConfig();
@@ -48,7 +49,8 @@ class MEDIA_EXPORT VideoDecoderConfig {
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
const gfx::Size& natural_size,
- const std::vector<uint8_t>& extra_data,
+ const uint8* extra_data,
+ size_t extra_data_size,
bool is_encrypted);
// Returns true if this object has appropriate configuration values, false
@@ -89,7 +91,8 @@ class MEDIA_EXPORT VideoDecoderConfig {
// Optional byte data required to initialize video decoders, such as H.264
// AAVC data.
- const std::vector<uint8_t>& extra_data() const { return extra_data_; }
+ const uint8* extra_data() const;
+ size_t extra_data_size() const { return extra_data_.size(); }
// Whether the video stream is potentially encrypted.
// Note that in a potentially encrypted video stream, individual buffers
@@ -107,7 +110,7 @@ class MEDIA_EXPORT VideoDecoderConfig {
gfx::Rect visible_rect_;
gfx::Size natural_size_;
- std::vector<uint8_t> extra_data_;
+ std::vector<uint8> extra_data_;
bool is_encrypted_;
diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc
index c9d8669..e6d5e91 100644
--- a/media/ffmpeg/ffmpeg_common.cc
+++ b/media/ffmpeg/ffmpeg_common.cc
@@ -6,7 +6,6 @@
#include "base/basictypes.h"
#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
#include "base/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
@@ -286,7 +285,7 @@ static AVSampleFormat SampleFormatToAVSampleFormat(SampleFormat sample_format) {
return AV_SAMPLE_FMT_NONE;
}
-bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context,
+void AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context,
bool is_encrypted,
AudioDecoderConfig* config) {
DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO);
@@ -320,26 +319,12 @@ bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context,
codec_context->seek_preroll * 1000000.0 / codec_context->sample_rate);
}
- // AVStream occasionally has invalid extra data. See http://crbug.com/517163
- if ((codec_context->extradata_size == 0) !=
- (codec_context->extradata == nullptr)) {
- LOG(ERROR) << __FUNCTION__
- << (codec_context->extradata == nullptr ? " NULL" : " Non-NULL")
- << " extra data cannot have size of "
- << codec_context->extradata_size << ".";
- return false;
- }
-
- std::vector<uint8_t> extra_data;
- if (codec_context->extradata_size > 0) {
- extra_data.assign(codec_context->extradata,
- codec_context->extradata + codec_context->extradata_size);
- }
config->Initialize(codec,
sample_format,
channel_layout,
sample_rate,
- extra_data,
+ codec_context->extradata,
+ codec_context->extradata_size,
is_encrypted,
seek_preroll,
codec_context->delay);
@@ -348,19 +333,15 @@ bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context,
DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8,
config->bits_per_channel());
}
-
- return true;
}
-bool AVStreamToAudioDecoderConfig(const AVStream* stream,
+void AVStreamToAudioDecoderConfig(const AVStream* stream,
AudioDecoderConfig* config) {
bool is_encrypted = false;
- AVDictionaryEntry* key =
- av_dict_get(stream->metadata, "enc_key_id", nullptr, 0);
+ AVDictionaryEntry* key = av_dict_get(stream->metadata, "enc_key_id", NULL, 0);
if (key)
is_encrypted = true;
- return AVCodecContextToAudioDecoderConfig(stream->codec, is_encrypted,
- config);
+ AVCodecContextToAudioDecoderConfig(stream->codec, is_encrypted, config);
}
void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config,
@@ -377,21 +358,21 @@ void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config,
ChannelLayoutToChannelCount(config.channel_layout());
codec_context->sample_rate = config.samples_per_second();
- if (config.extra_data().empty()) {
- codec_context->extradata = nullptr;
- codec_context->extradata_size = 0;
- } else {
- codec_context->extradata_size = config.extra_data().size();
+ if (config.extra_data()) {
+ codec_context->extradata_size = config.extra_data_size();
codec_context->extradata = reinterpret_cast<uint8_t*>(
- av_malloc(config.extra_data().size() + FF_INPUT_BUFFER_PADDING_SIZE));
- memcpy(codec_context->extradata, &config.extra_data()[0],
- config.extra_data().size());
- memset(codec_context->extradata + config.extra_data().size(), '\0',
+ av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE));
+ memcpy(codec_context->extradata, config.extra_data(),
+ config.extra_data_size());
+ memset(codec_context->extradata + config.extra_data_size(), '\0',
FF_INPUT_BUFFER_PADDING_SIZE);
+ } else {
+ codec_context->extradata = NULL;
+ codec_context->extradata_size = 0;
}
}
-bool AVStreamToVideoDecoderConfig(const AVStream* stream,
+void AVStreamToVideoDecoderConfig(const AVStream* stream,
VideoDecoderConfig* config) {
gfx::Size coded_size(stream->codec->coded_width, stream->codec->coded_height);
@@ -452,13 +433,12 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
}
bool is_encrypted = false;
- AVDictionaryEntry* key =
- av_dict_get(stream->metadata, "enc_key_id", nullptr, 0);
+ AVDictionaryEntry* key = av_dict_get(stream->metadata, "enc_key_id", NULL, 0);
if (key)
is_encrypted = true;
AVDictionaryEntry* webm_alpha =
- av_dict_get(stream->metadata, "alpha_mode", nullptr, 0);
+ av_dict_get(stream->metadata, "alpha_mode", NULL, 0);
if (webm_alpha && !strcmp(webm_alpha->value, "1")) {
format = PIXEL_FORMAT_YV12A;
}
@@ -473,24 +453,9 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
: COLOR_SPACE_HD_REC709;
}
- // AVStream occasionally has invalid extra data. See http://crbug.com/517163
- if ((stream->codec->extradata_size == 0) !=
- (stream->codec->extradata == nullptr)) {
- LOG(ERROR) << __FUNCTION__
- << (stream->codec->extradata == nullptr ? " NULL" : " Non-Null")
- << " extra data cannot have size of "
- << stream->codec->extradata_size << ".";
- return false;
- }
-
- std::vector<uint8_t> extra_data;
- if (stream->codec->extradata_size > 0) {
- extra_data.assign(stream->codec->extradata,
- stream->codec->extradata + stream->codec->extradata_size);
- }
config->Initialize(codec, profile, format, color_space, coded_size,
- visible_rect, natural_size, extra_data, is_encrypted);
- return true;
+ visible_rect, natural_size, stream->codec->extradata,
+ stream->codec->extradata_size, is_encrypted);
}
void VideoDecoderConfigToAVCodecContext(
@@ -505,17 +470,17 @@ void VideoDecoderConfigToAVCodecContext(
if (config.color_space() == COLOR_SPACE_JPEG)
codec_context->color_range = AVCOL_RANGE_JPEG;
- if (config.extra_data().empty()) {
- codec_context->extradata = nullptr;
- codec_context->extradata_size = 0;
- } else {
- codec_context->extradata_size = config.extra_data().size();
+ if (config.extra_data()) {
+ codec_context->extradata_size = config.extra_data_size();
codec_context->extradata = reinterpret_cast<uint8_t*>(
- av_malloc(config.extra_data().size() + FF_INPUT_BUFFER_PADDING_SIZE));
- memcpy(codec_context->extradata, &config.extra_data()[0],
- config.extra_data().size());
- memset(codec_context->extradata + config.extra_data().size(), '\0',
+ av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE));
+ memcpy(codec_context->extradata, config.extra_data(),
+ config.extra_data_size());
+ memset(codec_context->extradata + config.extra_data_size(), '\0',
FF_INPUT_BUFFER_PADDING_SIZE);
+ } else {
+ codec_context->extradata = NULL;
+ codec_context->extradata_size = 0;
}
}
diff --git a/media/ffmpeg/ffmpeg_common.h b/media/ffmpeg/ffmpeg_common.h
index f4a8237..677bd76 100644
--- a/media/ffmpeg/ffmpeg_common.h
+++ b/media/ffmpeg/ffmpeg_common.h
@@ -85,26 +85,19 @@ MEDIA_EXPORT base::TimeDelta ConvertFromTimeBase(const AVRational& time_base,
MEDIA_EXPORT int64 ConvertToTimeBase(const AVRational& time_base,
const base::TimeDelta& timestamp);
-// Returns true if AVStream is successfully converted to a AudioDecoderConfig.
-// Returns false if conversion fails, in which case |config| is not modified.
-MEDIA_EXPORT bool AVStreamToAudioDecoderConfig(const AVStream* stream,
- AudioDecoderConfig* config);
+void AVStreamToAudioDecoderConfig(const AVStream* stream,
+ AudioDecoderConfig* config);
void AudioDecoderConfigToAVCodecContext(
const AudioDecoderConfig& config,
AVCodecContext* codec_context);
-// Returns true if AVStream is successfully converted to a VideoDecoderConfig.
-// Returns false if conversion fails, in which case |config| is not modified.
-MEDIA_EXPORT bool AVStreamToVideoDecoderConfig(const AVStream* stream,
- VideoDecoderConfig* config);
+void AVStreamToVideoDecoderConfig(const AVStream* stream,
+ VideoDecoderConfig* config);
void VideoDecoderConfigToAVCodecContext(
const VideoDecoderConfig& config,
AVCodecContext* codec_context);
-// Returns true if AVCodecContext is successfully converted to an
-// AudioDecoderConfig. Returns false if conversion fails, in which case |config|
-// is not modified.
-MEDIA_EXPORT bool AVCodecContextToAudioDecoderConfig(
+MEDIA_EXPORT void AVCodecContextToAudioDecoderConfig(
const AVCodecContext* codec_context,
bool is_encrypted,
AudioDecoderConfig* config);
diff --git a/media/ffmpeg/ffmpeg_common_unittest.cc b/media/ffmpeg/ffmpeg_common_unittest.cc
index aa8a06d..ca68fa7 100644
--- a/media/ffmpeg/ffmpeg_common_unittest.cc
+++ b/media/ffmpeg/ffmpeg_common_unittest.cc
@@ -2,19 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <cstring>
-
-#include "base/bind.h"
-#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
-#include "media/base/audio_decoder_config.h"
#include "media/base/media.h"
-#include "media/base/test_data_util.h"
-#include "media/base/video_decoder_config.h"
#include "media/ffmpeg/ffmpeg_common.h"
#include "media/filters/ffmpeg_glue.h"
-#include "media/filters/in_memory_url_protocol.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
@@ -27,97 +19,6 @@ class FFmpegCommonTest : public testing::Test {
~FFmpegCommonTest() override{};
};
-uint8_t kExtraData[5] = {0x00, 0x01, 0x02, 0x03, 0x04};
-
-template <typename T>
-void TestConfigConvertExtraData(
- AVStream* stream,
- T* decoder_config,
- const base::Callback<bool(const AVStream*, T*)>& converter_fn) {
- // Should initially convert.
- EXPECT_TRUE(converter_fn.Run(stream, decoder_config));
-
- // Store orig to let FFmpeg free whatever it allocated.
- AVCodecContext* codec_context = stream->codec;
- uint8_t* orig_extradata = codec_context->extradata;
- int orig_extradata_size = codec_context->extradata_size;
-
- // Valid combination: extra_data = NULL && size = 0.
- codec_context->extradata = NULL;
- codec_context->extradata_size = 0;
- EXPECT_TRUE(converter_fn.Run(stream, decoder_config));
- EXPECT_EQ(static_cast<size_t>(codec_context->extradata_size),
- decoder_config->extra_data().size());
-
- // Valid combination: extra_data = non-NULL && size > 0.
- codec_context->extradata = &kExtraData[0];
- codec_context->extradata_size = arraysize(kExtraData);
- EXPECT_TRUE(converter_fn.Run(stream, decoder_config));
- EXPECT_EQ(static_cast<size_t>(codec_context->extradata_size),
- decoder_config->extra_data().size());
- EXPECT_EQ(0, memcmp(codec_context->extradata,
- &decoder_config->extra_data()[0],
- decoder_config->extra_data().size()));
-
- // Invalid combination: extra_data = NULL && size != 0.
- codec_context->extradata = NULL;
- codec_context->extradata_size = 10;
- EXPECT_FALSE(converter_fn.Run(stream, decoder_config));
-
- // Invalid combination: extra_data = non-NULL && size = 0.
- codec_context->extradata = &kExtraData[0];
- codec_context->extradata_size = 0;
- EXPECT_FALSE(converter_fn.Run(stream, decoder_config));
-
- // Restore orig values for sane cleanup.
- codec_context->extradata = orig_extradata;
- codec_context->extradata_size = orig_extradata_size;
-}
-
-TEST_F(FFmpegCommonTest, AVStreamToDecoderConfig) {
- // Open a file to get a real AVStreams from FFmpeg.
- base::MemoryMappedFile file;
- file.Initialize(GetTestDataFilePath("bear-320x240.webm"));
- InMemoryUrlProtocol protocol(file.data(), file.length(), false);
- FFmpegGlue glue(&protocol);
- ASSERT_TRUE(glue.OpenContext());
- AVFormatContext* format_context = glue.format_context();
-
- // Find the audio and video streams and test valid and invalid combinations
- // for extradata and extradata_size.
- bool found_audio = false;
- bool found_video = false;
- for (size_t i = 0;
- i < format_context->nb_streams && (!found_audio || !found_video);
- ++i) {
- AVStream* stream = format_context->streams[i];
- AVCodecContext* codec_context = stream->codec;
- AVMediaType codec_type = codec_context->codec_type;
-
- if (codec_type == AVMEDIA_TYPE_AUDIO) {
- if (found_audio)
- continue;
- found_audio = true;
- AudioDecoderConfig audio_config;
- TestConfigConvertExtraData(stream, &audio_config,
- base::Bind(&AVStreamToAudioDecoderConfig));
- } else if (codec_type == AVMEDIA_TYPE_VIDEO) {
- if (found_video)
- continue;
- found_video = true;
- VideoDecoderConfig video_config;
- TestConfigConvertExtraData(stream, &video_config,
- base::Bind(&AVStreamToVideoDecoderConfig));
- } else {
- // Only process audio/video.
- continue;
- }
- }
-
- ASSERT_TRUE(found_audio);
- ASSERT_TRUE(found_video);
-}
-
TEST_F(FFmpegCommonTest, OpusAudioDecoderConfig) {
AVCodecContext context = {0};
context.codec_type = AVMEDIA_TYPE_AUDIO;
@@ -130,8 +31,7 @@ TEST_F(FFmpegCommonTest, OpusAudioDecoderConfig) {
context.sample_rate = 44100;
AudioDecoderConfig decoder_config;
- ASSERT_TRUE(AVCodecContextToAudioDecoderConfig(&context, false,
- &decoder_config));
+ AVCodecContextToAudioDecoderConfig(&context, false, &decoder_config);
EXPECT_EQ(48000, decoder_config.samples_per_second());
}
diff --git a/media/filters/audio_decoder_selector_unittest.cc b/media/filters/audio_decoder_selector_unittest.cc
index 2b7f390..7b58a74 100644
--- a/media/filters/audio_decoder_selector_unittest.cc
+++ b/media/filters/audio_decoder_selector_unittest.cc
@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "media/base/gmock_callback_support.h"
-#include "media/base/media_util.h"
#include "media/base/mock_filters.h"
#include "media/base/test_helpers.h"
#include "media/filters/decoder_selector.h"
@@ -78,16 +77,16 @@ class AudioDecoderSelectorTest : public ::testing::Test {
}
void UseClearStream() {
- AudioDecoderConfig clear_audio_config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, 44100,
- EmptyExtraData(), false);
+ AudioDecoderConfig clear_audio_config(
+ kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100,
+ NULL, 0, false);
demuxer_stream_->set_audio_decoder_config(clear_audio_config);
}
void UseEncryptedStream() {
AudioDecoderConfig encrypted_audio_config(
kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100,
- EmptyExtraData(), true);
+ NULL, 0, true);
demuxer_stream_->set_audio_decoder_config(encrypted_audio_config);
}
diff --git a/media/filters/audio_decoder_unittest.cc b/media/filters/audio_decoder_unittest.cc
index 3ee51f4..83c2ea5 100644
--- a/media/filters/audio_decoder_unittest.cc
+++ b/media/filters/audio_decoder_unittest.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include <deque>
-#include <vector>
#include "base/bind.h"
#include "base/format_macros.h"
@@ -17,7 +16,6 @@
#include "media/base/audio_bus.h"
#include "media/base/audio_hash.h"
#include "media/base/decoder_buffer.h"
-#include "media/base/media_util.h"
#include "media/base/test_data_util.h"
#include "media/base/test_helpers.h"
#include "media/base/timestamp_constants.h"
@@ -153,8 +151,8 @@ class AudioDecoderTest : public testing::TestWithParam<DecoderTestData> {
ASSERT_TRUE(reader_->SeekForTesting(start_timestamp_));
AudioDecoderConfig config;
- ASSERT_TRUE(AVCodecContextToAudioDecoderConfig(
- reader_->codec_context_for_testing(), false, &config));
+ AVCodecContextToAudioDecoderConfig(reader_->codec_context_for_testing(),
+ false, &config);
EXPECT_EQ(GetParam().codec, config.codec());
EXPECT_EQ(GetParam().samples_per_second, config.samples_per_second());
@@ -376,15 +374,13 @@ TEST_P(AudioDecoderTest, NoTimestamp) {
TEST_P(OpusAudioDecoderBehavioralTest, InitializeWithNoCodecDelay) {
ASSERT_EQ(GetParam().decoder_type, OPUS);
- std::vector<uint8_t> extra_data(
- kOpusExtraData,
- kOpusExtraData + arraysize(kOpusExtraData));
AudioDecoderConfig decoder_config;
decoder_config.Initialize(kCodecOpus,
kSampleFormatF32,
CHANNEL_LAYOUT_STEREO,
48000,
- extra_data,
+ kOpusExtraData,
+ arraysize(kOpusExtraData),
false,
base::TimeDelta::FromMilliseconds(80),
0);
@@ -393,16 +389,14 @@ TEST_P(OpusAudioDecoderBehavioralTest, InitializeWithNoCodecDelay) {
TEST_P(OpusAudioDecoderBehavioralTest, InitializeWithBadCodecDelay) {
ASSERT_EQ(GetParam().decoder_type, OPUS);
- std::vector<uint8_t> extra_data(
- kOpusExtraData,
- kOpusExtraData + arraysize(kOpusExtraData));
AudioDecoderConfig decoder_config;
decoder_config.Initialize(
kCodecOpus,
kSampleFormatF32,
CHANNEL_LAYOUT_STEREO,
48000,
- extra_data,
+ kOpusExtraData,
+ arraysize(kOpusExtraData),
false,
base::TimeDelta::FromMilliseconds(80),
// Use a different codec delay than in the extradata.
@@ -416,7 +410,8 @@ TEST_P(FFmpegAudioDecoderBehavioralTest, InitializeWithBadConfig) {
CHANNEL_LAYOUT_STEREO,
// Invalid sample rate of zero.
0,
- EmptyExtraData(),
+ NULL,
+ 0,
false);
InitializeDecoderWithResult(decoder_config, false);
}
diff --git a/media/filters/chunk_demuxer_unittest.cc b/media/filters/chunk_demuxer_unittest.cc
index 1b6b894..747e512 100644
--- a/media/filters/chunk_demuxer_unittest.cc
+++ b/media/filters/chunk_demuxer_unittest.cc
@@ -736,8 +736,8 @@ class ChunkDemuxerTest : public ::testing::Test {
// bear-320x240.webm : [0-501) [801-2736)
// bear-640x360.webm : [527-793)
//
- // bear-320x240.webm AudioDecoderConfig returns 3863 for its extra_data size.
- // bear-640x360.webm AudioDecoderConfig returns 3935 for its extra_data size.
+ // bear-320x240.webm AudioDecoderConfig returns 3863 for its extra_data_size()
+ // bear-640x360.webm AudioDecoderConfig returns 3935 for its extra_data_size()
// The resulting audio stream returns data from each file for the following
// time ranges.
// bear-320x240.webm : [0-524) [779-2736)
@@ -1247,7 +1247,8 @@ TEST_F(ChunkDemuxerTest, Init) {
EXPECT_EQ(32, config.bits_per_channel());
EXPECT_EQ(CHANNEL_LAYOUT_STEREO, config.channel_layout());
EXPECT_EQ(44100, config.samples_per_second());
- EXPECT_GT(config.extra_data().size(), 0u);
+ EXPECT_TRUE(config.extra_data());
+ EXPECT_GT(config.extra_data_size(), 0u);
EXPECT_EQ(kSampleFormatPlanarF32, config.sample_format());
EXPECT_EQ(is_audio_encrypted,
audio_stream->audio_decoder_config().is_encrypted());
@@ -1316,7 +1317,8 @@ TEST_F(ChunkDemuxerTest, InitText) {
EXPECT_EQ(32, config.bits_per_channel());
EXPECT_EQ(CHANNEL_LAYOUT_STEREO, config.channel_layout());
EXPECT_EQ(44100, config.samples_per_second());
- EXPECT_GT(config.extra_data().size(), 0u);
+ EXPECT_TRUE(config.extra_data());
+ EXPECT_GT(config.extra_data_size(), 0u);
EXPECT_EQ(kSampleFormatPlanarF32, config.sample_format());
EXPECT_EQ(is_audio_encrypted,
audio_stream->audio_decoder_config().is_encrypted());
@@ -2885,7 +2887,7 @@ TEST_F(ChunkDemuxerTest, ConfigChange_Audio) {
const AudioDecoderConfig& audio_config_1 = audio->audio_decoder_config();
ASSERT_TRUE(audio_config_1.IsValidConfig());
EXPECT_EQ(audio_config_1.samples_per_second(), 44100);
- EXPECT_EQ(audio_config_1.extra_data().size(), 3863u);
+ EXPECT_EQ(audio_config_1.extra_data_size(), 3863u);
ExpectRead(DemuxerStream::AUDIO, 0);
@@ -2899,7 +2901,7 @@ TEST_F(ChunkDemuxerTest, ConfigChange_Audio) {
const AudioDecoderConfig& audio_config_2 = audio->audio_decoder_config();
ASSERT_TRUE(audio_config_2.IsValidConfig());
EXPECT_EQ(audio_config_2.samples_per_second(), 44100);
- EXPECT_EQ(audio_config_2.extra_data().size(), 3935u);
+ EXPECT_EQ(audio_config_2.extra_data_size(), 3935u);
// The next config change is from a splice frame representing an overlap of
// buffers from config 2 by buffers from config 1.
diff --git a/media/filters/decrypting_audio_decoder_unittest.cc b/media/filters/decrypting_audio_decoder_unittest.cc
index 4f749ce..d6ef2b9 100644
--- a/media/filters/decrypting_audio_decoder_unittest.cc
+++ b/media/filters/decrypting_audio_decoder_unittest.cc
@@ -12,7 +12,6 @@
#include "media/base/decoder_buffer.h"
#include "media/base/decrypt_config.h"
#include "media/base/gmock_callback_support.h"
-#include "media/base/media_util.h"
#include "media/base/mock_filters.h"
#include "media/base/test_helpers.h"
#include "media/base/timestamp_constants.h"
@@ -119,8 +118,8 @@ class DecryptingAudioDecoderTest : public testing::Test {
.WillOnce(SaveArg<1>(&key_added_cb_));
config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, kSampleRate, EmptyExtraData(),
- true, base::TimeDelta(), 0);
+ CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true,
+ base::TimeDelta(), 0);
InitializeAndExpectResult(config_, true);
}
@@ -288,8 +287,7 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) {
// Ensure that DecryptingAudioDecoder only accepts encrypted audio.
TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) {
AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, kSampleRate,
- EmptyExtraData(), false);
+ CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, false);
InitializeAndExpectResult(config, false);
}
@@ -297,7 +295,7 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) {
// Ensure decoder handles invalid audio configs without crashing.
TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) {
AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat,
- CHANNEL_LAYOUT_STEREO, 0, EmptyExtraData(), true);
+ CHANNEL_LAYOUT_STEREO, 0, NULL, 0, true);
InitializeAndExpectResult(config, false);
}
@@ -309,16 +307,14 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) {
ExpectDecryptorNotification(decryptor_.get(), true);
AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, kSampleRate,
- EmptyExtraData(), true);
+ CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true);
InitializeAndExpectResult(config, false);
}
TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) {
ExpectDecryptorNotification(NULL, false);
AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, kSampleRate,
- EmptyExtraData(), true);
+ CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true);
InitializeAndExpectResult(config, false);
}
@@ -386,8 +382,7 @@ TEST_F(DecryptingAudioDecoderTest, Reinitialize_ConfigChange) {
// The new config is different from the initial config in bits-per-channel,
// channel layout and samples_per_second.
AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
- CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(),
- true);
+ CHANNEL_LAYOUT_5_1, 88200, NULL, 0, true);
EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
EXPECT_NE(new_config.channel_layout(), config_.channel_layout());
EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second());
diff --git a/media/filters/decrypting_demuxer_stream.cc b/media/filters/decrypting_demuxer_stream.cc
index 3e67a29..ff98122 100644
--- a/media/filters/decrypting_demuxer_stream.cc
+++ b/media/filters/decrypting_demuxer_stream.cc
@@ -385,6 +385,7 @@ void DecryptingDemuxerStream::InitializeDecoderConfig() {
input_audio_config.channel_layout(),
input_audio_config.samples_per_second(),
input_audio_config.extra_data(),
+ input_audio_config.extra_data_size(),
false, // Output audio is not encrypted.
input_audio_config.seek_preroll(),
input_audio_config.codec_delay());
@@ -399,6 +400,7 @@ void DecryptingDemuxerStream::InitializeDecoderConfig() {
input_video_config.format(), input_video_config.color_space(),
input_video_config.coded_size(), input_video_config.visible_rect(),
input_video_config.natural_size(), input_video_config.extra_data(),
+ input_video_config.extra_data_size(),
false); // Output video is not encrypted.
break;
}
diff --git a/media/filters/decrypting_demuxer_stream_unittest.cc b/media/filters/decrypting_demuxer_stream_unittest.cc
index c679b56..e5a8f4b 100644
--- a/media/filters/decrypting_demuxer_stream_unittest.cc
+++ b/media/filters/decrypting_demuxer_stream_unittest.cc
@@ -11,7 +11,6 @@
#include "media/base/decoder_buffer.h"
#include "media/base/decrypt_config.h"
#include "media/base/gmock_callback_support.h"
-#include "media/base/media_util.h"
#include "media/base/mock_filters.h"
#include "media/base/test_helpers.h"
#include "media/filters/decrypting_demuxer_stream.h"
@@ -135,9 +134,9 @@ class DecryptingDemuxerStreamTest : public testing::Test {
EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
.WillOnce(SaveArg<1>(&key_added_cb_));
- AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, 44100,
- EmptyExtraData(), true);
+ AudioDecoderConfig input_config(
+ kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100,
+ NULL, 0, true);
InitializeAudioAndExpectStatus(input_config, PIPELINE_OK);
const AudioDecoderConfig& output_config =
@@ -310,14 +309,18 @@ TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalVideo) {
EXPECT_EQ(input_config.coded_size(), output_config.coded_size());
EXPECT_EQ(input_config.visible_rect(), output_config.visible_rect());
EXPECT_EQ(input_config.natural_size(), output_config.natural_size());
- ASSERT_EQ(input_config.extra_data(), output_config.extra_data());
+ ASSERT_EQ(input_config.extra_data_size(), output_config.extra_data_size());
+ if (input_config.extra_data_size() > 0) {
+ EXPECT_FALSE(output_config.extra_data());
+ EXPECT_EQ(0, memcmp(output_config.extra_data(), input_config.extra_data(),
+ input_config.extra_data_size()));
+ }
}
TEST_F(DecryptingDemuxerStreamTest, Initialize_NullDecryptor) {
ExpectDecryptorNotification(NULL, false);
AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, 44100,
- EmptyExtraData(), true);
+ CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true);
InitializeAudioAndExpectStatus(input_config, DECODER_ERROR_NOT_SUPPORTED);
}
@@ -391,9 +394,9 @@ TEST_F(DecryptingDemuxerStreamTest, Reset_DuringDecryptorRequested) {
// One for decryptor request, one for canceling request during Reset().
EXPECT_CALL(*this, RequestDecryptorNotification(_))
.Times(2);
- AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, 44100,
- EmptyExtraData(), true);
+ AudioDecoderConfig input_config(
+ kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100,
+ NULL, 0, true);
InitializeAudioAndExpectStatus(input_config, PIPELINE_ERROR_ABORT);
Reset();
}
@@ -479,9 +482,9 @@ TEST_F(DecryptingDemuxerStreamTest, Reset_DuringAbortedDemuxerRead) {
TEST_F(DecryptingDemuxerStreamTest, DemuxerRead_ConfigChanged) {
Initialize();
- AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, 88200, EmptyExtraData(),
- true);
+ AudioDecoderConfig new_config(
+ kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 88200, NULL,
+ 0, true);
input_audio_stream_->set_audio_decoder_config(new_config);
EXPECT_CALL(*input_audio_stream_, Read(_))
@@ -512,9 +515,9 @@ TEST_F(DecryptingDemuxerStreamTest, Destroy_DuringDecryptorRequested) {
// One for decryptor request, one for canceling request during Reset().
EXPECT_CALL(*this, RequestDecryptorNotification(_))
.Times(2);
- AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, 44100,
- EmptyExtraData(), true);
+ AudioDecoderConfig input_config(
+ kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100,
+ NULL, 0, true);
InitializeAudioAndExpectStatus(input_config, PIPELINE_ERROR_ABORT);
}
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
index c06dd29..155e980 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -172,58 +172,14 @@ static int32_t GetCodecHash(const AVCodecContext* context) {
return HashCodecName("none");
}
-scoped_ptr<FFmpegDemuxerStream> FFmpegDemuxerStream::Create(
- FFmpegDemuxer* demuxer,
- AVStream* stream) {
- if (!demuxer || !stream)
- return nullptr;
-
- scoped_ptr<FFmpegDemuxerStream> demuxer_stream;
- scoped_ptr<AudioDecoderConfig> audio_config;
- scoped_ptr<VideoDecoderConfig> video_config;
-
- if (stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
- audio_config.reset(new AudioDecoderConfig());
-
- // IsValidConfig() checks that the codec is supported and that the channel
- // layout and sample format are valid.
- //
- // TODO(chcunningham): Change AVStreamToAudioDecoderConfig to check
- // IsValidConfig internally and return a null scoped_ptr if not valid.
- if (!AVStreamToAudioDecoderConfig(stream, audio_config.get()) ||
- !audio_config->IsValidConfig())
- return nullptr;
-
- } else if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
- video_config.reset(new VideoDecoderConfig());
-
- // IsValidConfig() checks that the codec is supported and that the channel
- // layout and sample format are valid.
- //
- // TODO(chcunningham): Change AVStreamToVideoDecoderConfig to check
- // IsValidConfig internally and return a null scoped_ptr if not valid.
- if (!AVStreamToVideoDecoderConfig(stream, video_config.get()) ||
- !video_config->IsValidConfig())
- return nullptr;
- }
-
- return make_scoped_ptr(new FFmpegDemuxerStream(
- demuxer, stream, audio_config.Pass(), video_config.Pass()));
-}
-
//
// FFmpegDemuxerStream
//
-FFmpegDemuxerStream::FFmpegDemuxerStream(
- FFmpegDemuxer* demuxer,
- AVStream* stream,
- scoped_ptr<AudioDecoderConfig> audio_config,
- scoped_ptr<VideoDecoderConfig> video_config)
+FFmpegDemuxerStream::FFmpegDemuxerStream(FFmpegDemuxer* demuxer,
+ AVStream* stream)
: demuxer_(demuxer),
task_runner_(base::ThreadTaskRunnerHandle::Get()),
stream_(stream),
- audio_config_(audio_config.release()),
- video_config_(video_config.release()),
type_(UNKNOWN),
liveness_(LIVENESS_UNKNOWN),
end_of_stream_(false),
@@ -240,14 +196,14 @@ FFmpegDemuxerStream::FFmpegDemuxerStream(
// Determine our media format.
switch (stream->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
- DCHECK(audio_config_.get() && !video_config_.get());
type_ = AUDIO;
- is_encrypted = audio_config_->is_encrypted();
+ AVStreamToAudioDecoderConfig(stream, &audio_config_);
+ is_encrypted = audio_config_.is_encrypted();
break;
case AVMEDIA_TYPE_VIDEO:
- DCHECK(video_config_.get() && !audio_config_.get());
type_ = VIDEO;
- is_encrypted = video_config_->is_encrypted();
+ AVStreamToVideoDecoderConfig(stream, &video_config_);
+ is_encrypted = video_config_.is_encrypted();
rotation_entry = av_dict_get(stream->metadata, "rotate", NULL, 0);
if (rotation_entry && rotation_entry->value && rotation_entry->value[0])
@@ -272,7 +228,6 @@ FFmpegDemuxerStream::FFmpegDemuxerStream(
break;
case AVMEDIA_TYPE_SUBTITLE:
- DCHECK(!video_config_.get() && !audio_config_.get());
type_ = TEXT;
break;
default:
@@ -360,8 +315,8 @@ void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) {
scoped_ptr<DecryptConfig> decrypt_config;
int data_offset = 0;
- if ((type() == DemuxerStream::AUDIO && audio_config_->is_encrypted()) ||
- (type() == DemuxerStream::VIDEO && video_config_->is_encrypted())) {
+ if ((type() == DemuxerStream::AUDIO && audio_config_.is_encrypted()) ||
+ (type() == DemuxerStream::VIDEO && video_config_.is_encrypted())) {
if (!WebMCreateDecryptConfig(
packet->data, packet->size,
reinterpret_cast<const uint8*>(encryption_key_id_.data()),
@@ -625,16 +580,14 @@ bool FFmpegDemuxerStream::SupportsConfigChanges() { return false; }
AudioDecoderConfig FFmpegDemuxerStream::audio_decoder_config() {
DCHECK(task_runner_->BelongsToCurrentThread());
- DCHECK_EQ(type_, AUDIO);
- DCHECK(audio_config_.get());
- return *audio_config_;
+ CHECK_EQ(type_, AUDIO);
+ return audio_config_;
}
VideoDecoderConfig FFmpegDemuxerStream::video_decoder_config() {
DCHECK(task_runner_->BelongsToCurrentThread());
- DCHECK_EQ(type_, VIDEO);
- DCHECK(video_config_.get());
- return *video_config_;
+ CHECK_EQ(type_, VIDEO);
+ return video_config_;
}
VideoRotation FFmpegDemuxerStream::video_rotation() {
@@ -1034,6 +987,7 @@ void FFmpegDemuxer::OnFindStreamInfoDone(const PipelineStatusCB& status_cb,
AVStream* audio_stream = NULL;
AudioDecoderConfig audio_config;
+
AVStream* video_stream = NULL;
VideoDecoderConfig video_config;
@@ -1053,6 +1007,13 @@ void FFmpegDemuxer::OnFindStreamInfoDone(const PipelineStatusCB& status_cb,
// Log the codec detected, whether it is supported or not.
UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedAudioCodecHash",
GetCodecHash(codec_context));
+
+ // Ensure the codec is supported. IsValidConfig() also checks that the
+ // channel layout and sample format are valid.
+ AVStreamToAudioDecoderConfig(stream, &audio_config);
+ if (!audio_config.IsValidConfig())
+ continue;
+ audio_stream = stream;
} else if (codec_type == AVMEDIA_TYPE_VIDEO) {
if (video_stream)
continue;
@@ -1081,6 +1042,14 @@ void FFmpegDemuxer::OnFindStreamInfoDone(const PipelineStatusCB& status_cb,
// Log the codec detected, whether it is supported or not.
UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedVideoCodecHash",
GetCodecHash(codec_context));
+
+ // Ensure the codec is supported. IsValidConfig() also checks that the
+ // frame size and visible size are valid.
+ AVStreamToVideoDecoderConfig(stream, &video_config);
+
+ if (!video_config.IsValidConfig())
+ continue;
+ video_stream = stream;
} else if (codec_type == AVMEDIA_TYPE_SUBTITLE) {
if (codec_context->codec_id != AV_CODEC_ID_WEBVTT || !text_enabled_) {
continue;
@@ -1089,30 +1058,15 @@ void FFmpegDemuxer::OnFindStreamInfoDone(const PipelineStatusCB& status_cb,
continue;
}
- // Attempt to create a FFmpegDemuxerStream from the AVStream. This will
- // return nullptr if the AVStream is invalid. Validity checks will verify
- // things like: codec, channel layout, sample/pixel format, etc...
- scoped_ptr<FFmpegDemuxerStream> demuxer_stream =
- FFmpegDemuxerStream::Create(this, stream);
- if (demuxer_stream.get()) {
- streams_[i] = demuxer_stream.release();
- } else {
- // This AVStream does not successfully convert.
- continue;
- }
+ streams_[i] = new FFmpegDemuxerStream(this, stream);
- // Note when we find our audio/video stream (we only want one of each) and
- // record src= playback UMA stats for the stream's decoder config.
+ // Record audio or video src= playback UMA stats for the stream's decoder
+ // config.
if (codec_type == AVMEDIA_TYPE_AUDIO) {
- CHECK(!audio_stream);
- audio_stream = stream;
- audio_config = streams_[i]->audio_decoder_config();
- RecordAudioCodecStats(audio_config);
+ RecordAudioCodecStats(streams_[i]->audio_decoder_config());
} else if (codec_type == AVMEDIA_TYPE_VIDEO) {
- CHECK(!video_stream);
- video_stream = stream;
- video_config = streams_[i]->video_decoder_config();
- RecordVideoCodecStats(video_config, stream->codec->color_range);
+ RecordVideoCodecStats(streams_[i]->video_decoder_config(),
+ stream->codec->color_range);
}
max_duration = std::max(max_duration, streams_[i]->duration());
diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h
index 96c21d5..9c20e4a 100644
--- a/media/filters/ffmpeg_demuxer.h
+++ b/media/filters/ffmpeg_demuxer.h
@@ -27,7 +27,6 @@
#include <vector>
#include "base/callback.h"
-#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/threading/thread.h"
#include "media/base/audio_decoder_config.h"
@@ -56,14 +55,9 @@ typedef scoped_ptr<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket;
class FFmpegDemuxerStream : public DemuxerStream {
public:
- // Attempts to create FFmpegDemuxerStream form the given AVStream. Will return
- // null if the AVStream cannot be translated into a valid decoder config.
- //
- // FFmpegDemuxerStream keeps a copy of |demuxer| and initializes itself using
- // information inside |stream|. Both parameters must outlive |this|.
- static scoped_ptr<FFmpegDemuxerStream> Create(FFmpegDemuxer* demuxer,
- AVStream* stream);
-
+ // Keeps a copy of |demuxer| and initializes itself using information inside
+ // |stream|. Both parameters must outlive |this|.
+ FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream);
~FFmpegDemuxerStream() override;
// Enqueues the given AVPacket. It is invalid to queue a |packet| after
@@ -129,15 +123,6 @@ class FFmpegDemuxerStream : public DemuxerStream {
private:
friend class FFmpegDemuxerTest;
- // Use FFmpegDemuxerStream::Create to construct.
- // Audio/Video streams must include their respective DecoderConfig. At most
- // one DecoderConfig should be provided (leaving the other nullptr). Both
- // configs should be null for text streams.
- FFmpegDemuxerStream(FFmpegDemuxer* demuxer,
- AVStream* stream,
- scoped_ptr<AudioDecoderConfig> audio_config,
- scoped_ptr<VideoDecoderConfig> video_config);
-
// Runs |read_cb_| if present with the front of |buffer_queue_|, calling
// NotifyCapacityAvailable() if capacity is still available.
void SatisfyPendingRead();
@@ -155,8 +140,8 @@ class FFmpegDemuxerStream : public DemuxerStream {
FFmpegDemuxer* demuxer_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
AVStream* stream_;
- scoped_ptr<AudioDecoderConfig> audio_config_;
- scoped_ptr<VideoDecoderConfig> video_config_;
+ AudioDecoderConfig audio_config_;
+ VideoDecoderConfig video_config_;
Type type_;
Liveness liveness_;
base::TimeDelta duration_;
diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc
index 2e988d2..e75a67f 100644
--- a/media/filters/ffmpeg_demuxer_unittest.cc
+++ b/media/filters/ffmpeg_demuxer_unittest.cc
@@ -296,7 +296,8 @@ TEST_F(FFmpegDemuxerTest, Initialize_Successful) {
EXPECT_EQ(240, video_config.visible_rect().height());
EXPECT_EQ(320, video_config.natural_size().width());
EXPECT_EQ(240, video_config.natural_size().height());
- EXPECT_TRUE(video_config.extra_data().empty());
+ EXPECT_FALSE(video_config.extra_data());
+ EXPECT_EQ(0u, video_config.extra_data_size());
// Audio stream should be present.
stream = demuxer_->GetStream(DemuxerStream::AUDIO);
@@ -309,7 +310,8 @@ TEST_F(FFmpegDemuxerTest, Initialize_Successful) {
EXPECT_EQ(CHANNEL_LAYOUT_STEREO, audio_config.channel_layout());
EXPECT_EQ(44100, audio_config.samples_per_second());
EXPECT_EQ(kSampleFormatPlanarF32, audio_config.sample_format());
- EXPECT_FALSE(audio_config.extra_data().empty());
+ EXPECT_TRUE(audio_config.extra_data());
+ EXPECT_GT(audio_config.extra_data_size(), 0u);
// Unknown stream should never be present.
EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN));
diff --git a/media/filters/ffmpeg_glue.cc b/media/filters/ffmpeg_glue.cc
index bfeced0..31c6828 100644
--- a/media/filters/ffmpeg_glue.cc
+++ b/media/filters/ffmpeg_glue.cc
@@ -153,7 +153,7 @@ FFmpegGlue::FFmpegGlue(FFmpegURLProtocol* protocol)
}
bool FFmpegGlue::OpenContext() {
- DCHECK(!open_called_) << "OpenContext() shouldn't be called twice.";
+ DCHECK(!open_called_) << "OpenContext() should't be called twice.";
// If avformat_open_input() is called we have to take a slightly different
// destruction path to avoid double frees.
diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc
index 4a1be85..f8a954a 100644
--- a/media/filters/ffmpeg_video_decoder_unittest.cc
+++ b/media/filters/ffmpeg_video_decoder_unittest.cc
@@ -14,7 +14,6 @@
#include "media/base/decoder_buffer.h"
#include "media/base/gmock_callback_support.h"
#include "media/base/limits.h"
-#include "media/base/media_util.h"
#include "media/base/mock_filters.h"
#include "media/base/test_data_util.h"
#include "media/base/test_helpers.h"
@@ -225,17 +224,17 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedPixelFormat) {
// Ensure decoder handles unsupported pixel formats without crashing.
VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN,
PIXEL_FORMAT_UNKNOWN, COLOR_SPACE_UNSPECIFIED,
- kCodedSize, kVisibleRect, kNaturalSize,
- EmptyExtraData(), false);
+ kCodedSize, kVisibleRect, kNaturalSize, NULL, 0,
+ false);
InitializeWithConfigWithResult(config, false);
}
TEST_F(FFmpegVideoDecoderTest, Initialize_OpenDecoderFails) {
// Specify Theora w/o extra data so that avcodec_open2() fails.
VideoDecoderConfig config(kCodecTheora, VIDEO_CODEC_PROFILE_UNKNOWN,
- kVideoFormat, COLOR_SPACE_UNSPECIFIED, kCodedSize,
- kVisibleRect, kNaturalSize, EmptyExtraData(),
- false);
+ kVideoFormat, COLOR_SPACE_UNSPECIFIED,
+ kCodedSize, kVisibleRect, kNaturalSize,
+ NULL, 0, false);
InitializeWithConfigWithResult(config, false);
}
@@ -248,7 +247,8 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorZero) {
kCodedSize,
kVisibleRect,
natural_size,
- EmptyExtraData(),
+ NULL,
+ 0,
false);
InitializeWithConfigWithResult(config, false);
}
@@ -262,7 +262,8 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorZero) {
kCodedSize,
kVisibleRect,
natural_size,
- EmptyExtraData(),
+ NULL,
+ 0,
false);
InitializeWithConfigWithResult(config, false);
}
@@ -276,7 +277,8 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorNegative) {
kCodedSize,
kVisibleRect,
natural_size,
- EmptyExtraData(),
+ NULL,
+ 0,
false);
InitializeWithConfigWithResult(config, false);
}
@@ -290,7 +292,8 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorNegative) {
kCodedSize,
kVisibleRect,
natural_size,
- EmptyExtraData(),
+ NULL,
+ 0,
false);
InitializeWithConfigWithResult(config, false);
}
@@ -306,7 +309,8 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorTooLarge) {
kCodedSize,
kVisibleRect,
natural_size,
- EmptyExtraData(),
+ NULL,
+ 0,
false);
InitializeWithConfigWithResult(config, false);
}
@@ -323,7 +327,8 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorTooLarge) {
kCodedSize,
kVisibleRect,
natural_size,
- EmptyExtraData(),
+ NULL,
+ 0,
false);
InitializeWithConfigWithResult(config, false);
}
diff --git a/media/filters/frame_processor_unittest.cc b/media/filters/frame_processor_unittest.cc
index 4440de0..ed4e715 100644
--- a/media/filters/frame_processor_unittest.cc
+++ b/media/filters/frame_processor_unittest.cc
@@ -4,7 +4,6 @@
#include <map>
#include <string>
-#include <vector>
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
@@ -13,7 +12,6 @@
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "media/base/media_log.h"
-#include "media/base/media_util.h"
#include "media/base/mock_filters.h"
#include "media/base/test_helpers.h"
#include "media/base/timestamp_constants.h"
@@ -284,9 +282,13 @@ class FrameProcessorTest : public testing::TestWithParam<bool> {
case DemuxerStream::AUDIO: {
ASSERT_FALSE(audio_);
audio_.reset(new ChunkDemuxerStream(DemuxerStream::AUDIO, true));
- AudioDecoderConfig decoder_config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, 1000,
- EmptyExtraData(), false);
+ AudioDecoderConfig decoder_config(kCodecVorbis,
+ kSampleFormatPlanarF32,
+ CHANNEL_LAYOUT_STEREO,
+ 1000,
+ NULL,
+ 0,
+ false);
frame_processor_->OnPossibleAudioConfigUpdate(decoder_config);
ASSERT_TRUE(audio_->UpdateAudioConfig(decoder_config, new MediaLog()));
break;
diff --git a/media/filters/opus_audio_decoder.cc b/media/filters/opus_audio_decoder.cc
index 41e06fb..c0fde49 100644
--- a/media/filters/opus_audio_decoder.cc
+++ b/media/filters/opus_audio_decoder.cc
@@ -358,9 +358,7 @@ bool OpusAudioDecoder::ConfigureDecoder() {
// Parse the Opus Extra Data.
OpusExtraData opus_extra_data;
- if (!ParseOpusExtraData(config_.extra_data().empty() ? nullptr :
- &config_.extra_data()[0],
- config_.extra_data().size(),
+ if (!ParseOpusExtraData(config_.extra_data(), config_.extra_data_size(),
config_,
&opus_extra_data))
return false;
diff --git a/media/filters/source_buffer_stream_unittest.cc b/media/filters/source_buffer_stream_unittest.cc
index 5d8dfd5..bf15f32 100644
--- a/media/filters/source_buffer_stream_unittest.cc
+++ b/media/filters/source_buffer_stream_unittest.cc
@@ -6,7 +6,6 @@
#include <stdint.h>
#include <string>
-#include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
@@ -16,7 +15,6 @@
#include "base/strings/string_util.h"
#include "media/base/data_buffer.h"
#include "media/base/media_log.h"
-#include "media/base/media_util.h"
#include "media/base/mock_media_log.h"
#include "media/base/test_helpers.h"
#include "media/base/text_track_config.h"
@@ -103,7 +101,8 @@ class SourceBufferStreamTest : public testing::Test {
kSampleFormatPlanarF32,
CHANNEL_LAYOUT_STEREO,
1000,
- EmptyExtraData(),
+ NULL,
+ 0,
false,
base::TimeDelta(),
0);
@@ -3604,7 +3603,7 @@ TEST_F(SourceBufferStreamTest, SameTimestamp_Video_Overlap_3) {
// Test all the valid same timestamp cases for audio.
TEST_F(SourceBufferStreamTest, SameTimestamp_Audio) {
AudioDecoderConfig config(kCodecMP3, kSampleFormatF32, CHANNEL_LAYOUT_STEREO,
- 44100, EmptyExtraData(), false);
+ 44100, NULL, 0, false);
stream_.reset(new SourceBufferStream(config, media_log_, true));
Seek(0);
NewSegmentAppend("0K 0K 30K 30 60 60");
@@ -3615,7 +3614,7 @@ TEST_F(SourceBufferStreamTest, SameTimestamp_Audio_Invalid_1) {
EXPECT_MEDIA_LOG(ContainsSameTimestampAt30MillisecondsLog());
AudioDecoderConfig config(kCodecMP3, kSampleFormatF32, CHANNEL_LAYOUT_STEREO,
- 44100, EmptyExtraData(), false);
+ 44100, NULL, 0, false);
stream_.reset(new SourceBufferStream(config, media_log_, true));
Seek(0);
NewSegmentAppend_ExpectFailure("0K 30 30K 60");
@@ -4174,8 +4173,12 @@ TEST_F(SourceBufferStreamTest, Audio_SpliceFrame_ConfigChange) {
SetAudioStream();
- AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_MONO, 1000, EmptyExtraData(),
+ AudioDecoderConfig new_config(kCodecVorbis,
+ kSampleFormatPlanarF32,
+ CHANNEL_LAYOUT_MONO,
+ 1000,
+ NULL,
+ 0,
false);
ASSERT_NE(new_config.channel_layout(), audio_config_.channel_layout());
@@ -4217,7 +4220,7 @@ TEST_F(SourceBufferStreamTest, Audio_SpliceFrame_NoMillisecondSplices) {
video_config_ = TestVideoConfig::Invalid();
audio_config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, 4000, EmptyExtraData(), false,
+ CHANNEL_LAYOUT_STEREO, 4000, NULL, 0, false,
base::TimeDelta(), 0);
stream_.reset(new SourceBufferStream(audio_config_, media_log_, true));
// Equivalent to 0.5ms per frame.
diff --git a/media/formats/mp2t/es_adapter_video_unittest.cc b/media/formats/mp2t/es_adapter_video_unittest.cc
index 24feb85..396b655 100644
--- a/media/formats/mp2t/es_adapter_video_unittest.cc
+++ b/media/formats/mp2t/es_adapter_video_unittest.cc
@@ -10,7 +10,6 @@
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
-#include "media/base/media_util.h"
#include "media/base/stream_parser_buffer.h"
#include "media/base/timestamp_constants.h"
#include "media/base/video_decoder_config.h"
@@ -28,7 +27,7 @@ VideoDecoderConfig CreateFakeVideoConfig() {
gfx::Size natural_size(320, 240);
return VideoDecoderConfig(kCodecH264, H264PROFILE_MAIN, PIXEL_FORMAT_I420,
COLOR_SPACE_UNSPECIFIED, coded_size, visible_rect,
- natural_size, EmptyExtraData(), false);
+ natural_size, NULL, 0, false);
}
StreamParserBuffer::BufferQueue
diff --git a/media/formats/mp2t/es_parser_adts.cc b/media/formats/mp2t/es_parser_adts.cc
index adf1dbe..9c57de1 100644
--- a/media/formats/mp2t/es_parser_adts.cc
+++ b/media/formats/mp2t/es_parser_adts.cc
@@ -4,8 +4,6 @@
#include "media/formats/mp2t/es_parser_adts.h"
-#include <vector>
-
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
@@ -221,9 +219,10 @@ bool EsParserAdts::UpdateAudioConfiguration(const uint8* adts_header) {
(frequency_index << 7) +
// channel_configuration is [0..7], per early out above.
(channel_configuration << 3));
- std::vector<uint8_t> extra_data;
- extra_data.push_back(static_cast<uint8>(extra_data_int >> 8));
- extra_data.push_back(static_cast<uint8>(extra_data_int & 0xff));
+ uint8 extra_data[2] = {
+ static_cast<uint8>(extra_data_int >> 8),
+ static_cast<uint8>(extra_data_int & 0xff)
+ };
AudioDecoderConfig audio_decoder_config(
kCodecAAC,
@@ -231,6 +230,7 @@ bool EsParserAdts::UpdateAudioConfiguration(const uint8* adts_header) {
kADTSChannelLayoutTable[channel_configuration],
extended_samples_per_second,
extra_data,
+ arraysize(extra_data),
false);
if (!audio_decoder_config.Matches(last_audio_decoder_config_)) {
diff --git a/media/formats/mp2t/es_parser_h264.cc b/media/formats/mp2t/es_parser_h264.cc
index 8c59112..cbdec71 100644
--- a/media/formats/mp2t/es_parser_h264.cc
+++ b/media/formats/mp2t/es_parser_h264.cc
@@ -280,8 +280,8 @@ bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps) {
VideoDecoderConfig video_decoder_config(
kCodecH264, VIDEO_CODEC_PROFILE_UNKNOWN, PIXEL_FORMAT_YV12,
- COLOR_SPACE_HD_REC709, coded_size, visible_rect, natural_size,
- std::vector<uint8_t>(), false);
+ COLOR_SPACE_HD_REC709, coded_size, visible_rect, natural_size, NULL, 0,
+ false);
if (!video_decoder_config.Matches(last_video_decoder_config_)) {
DVLOG(1) << "Profile IDC: " << sps->profile_idc;
diff --git a/media/formats/mp2t/es_parser_mpeg1audio.cc b/media/formats/mp2t/es_parser_mpeg1audio.cc
index 81abc2b..aee4cba 100644
--- a/media/formats/mp2t/es_parser_mpeg1audio.cc
+++ b/media/formats/mp2t/es_parser_mpeg1audio.cc
@@ -4,8 +4,6 @@
#include "media/formats/mp2t/es_parser_mpeg1audio.h"
-#include <vector>
-
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/logging.h"
@@ -175,7 +173,7 @@ bool EsParserMpeg1Audio::UpdateAudioConfiguration(
kSampleFormatS16,
header.channel_layout,
header.sample_rate,
- std::vector<uint8_t>(),
+ NULL, 0,
false);
if (!audio_decoder_config.Matches(last_audio_decoder_config_)) {
diff --git a/media/formats/mp4/mp4_stream_parser.cc b/media/formats/mp4/mp4_stream_parser.cc
index 78b7dcd..18698b3 100644
--- a/media/formats/mp4/mp4_stream_parser.cc
+++ b/media/formats/mp4/mp4_stream_parser.cc
@@ -4,8 +4,6 @@
#include "media/formats/mp4/mp4_stream_parser.h"
-#include <vector>
-
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/time/time.h"
@@ -268,9 +266,10 @@ bool MP4StreamParser::ParseMoov(BoxReader* reader) {
is_audio_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted;
DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_;
- audio_config.Initialize(codec, sample_format, channel_layout,
- sample_per_second, extra_data,
- is_audio_track_encrypted_, base::TimeDelta(), 0);
+ audio_config.Initialize(
+ codec, sample_format, channel_layout, sample_per_second,
+ extra_data.size() ? &extra_data[0] : NULL, extra_data.size(),
+ is_audio_track_encrypted_, base::TimeDelta(), 0);
has_audio_ = true;
audio_track_id_ = track->header.track_id;
}
@@ -306,12 +305,12 @@ bool MP4StreamParser::ParseMoov(BoxReader* reader) {
is_video_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted;
DVLOG(1) << "is_video_track_encrypted_: " << is_video_track_encrypted_;
- video_config.Initialize(
- entry.video_codec, entry.video_codec_profile, PIXEL_FORMAT_YV12,
- COLOR_SPACE_HD_REC709, coded_size, visible_rect, natural_size,
- // No decoder-specific buffer needed for AVC;
- // SPS/PPS are embedded in the video stream
- std::vector<uint8_t>(), is_video_track_encrypted_);
+ video_config.Initialize(entry.video_codec, entry.video_codec_profile,
+ PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709,
+ coded_size, visible_rect, natural_size,
+ // No decoder-specific buffer needed for AVC;
+ // SPS/PPS are embedded in the video stream
+ NULL, 0, is_video_track_encrypted_);
has_video_ = true;
video_track_id_ = track->header.track_id;
}
diff --git a/media/formats/mpeg/mpeg_audio_stream_parser_base.cc b/media/formats/mpeg/mpeg_audio_stream_parser_base.cc
index 23032fa..d9bf2b5 100644
--- a/media/formats/mpeg/mpeg_audio_stream_parser_base.cc
+++ b/media/formats/mpeg/mpeg_audio_stream_parser_base.cc
@@ -207,7 +207,8 @@ int MPEGAudioStreamParserBase::ParseFrame(const uint8* data,
kSampleFormatF32,
channel_layout,
sample_rate,
- std::vector<uint8_t>(),
+ NULL,
+ 0,
false,
base::TimeDelta(),
codec_delay_);
diff --git a/media/formats/webm/webm_audio_client.cc b/media/formats/webm/webm_audio_client.cc
index 995746a4..bde7233 100644
--- a/media/formats/webm/webm_audio_client.cc
+++ b/media/formats/webm/webm_audio_client.cc
@@ -66,6 +66,13 @@ bool WebMAudioClient::InitializeConfig(
sample_format = kSampleFormatF32;
}
+ const uint8* extra_data = NULL;
+ size_t extra_data_size = 0;
+ if (codec_private.size() > 0) {
+ extra_data = &codec_private[0];
+ extra_data_size = codec_private.size();
+ }
+
// Convert |codec_delay| from nanoseconds into frames.
int codec_delay_in_frames = 0;
if (codec_delay != -1) {
@@ -80,7 +87,8 @@ bool WebMAudioClient::InitializeConfig(
sample_format,
channel_layout,
samples_per_second,
- codec_private,
+ extra_data,
+ extra_data_size,
is_encrypted,
base::TimeDelta::FromMicroseconds(
(seek_preroll != -1 ? seek_preroll : 0) / 1000),
diff --git a/media/formats/webm/webm_video_client.cc b/media/formats/webm/webm_video_client.cc
index 29b7dca..2d3f43b 100644
--- a/media/formats/webm/webm_video_client.cc
+++ b/media/formats/webm/webm_video_client.cc
@@ -88,10 +88,16 @@ bool WebMVideoClient::InitializeConfig(
return false;
}
gfx::Size natural_size = gfx::Size(display_width_, display_height_);
+ const uint8* extra_data = NULL;
+ size_t extra_data_size = 0;
+ if (codec_private.size() > 0) {
+ extra_data = &codec_private[0];
+ extra_data_size = codec_private.size();
+ }
config->Initialize(video_codec, profile, format, COLOR_SPACE_HD_REC709,
- coded_size, visible_rect, natural_size, codec_private,
- is_encrypted);
+ coded_size, visible_rect, natural_size, extra_data,
+ extra_data_size, is_encrypted);
return config->IsValidConfig();
}
diff --git a/media/media.gyp b/media/media.gyp
index f0e41703..897c5d9 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -328,8 +328,6 @@
'base/media_resources.h',
'base/media_switches.cc',
'base/media_switches.h',
- 'base/media_util.cc',
- 'base/media_util.h',
'base/mime_util.cc',
'base/mime_util.h',
'base/moving_average.cc',
diff --git a/media/mojo/services/media_type_converters.cc b/media/mojo/services/media_type_converters.cc
index bcfab49..6dd84fb 100644
--- a/media/mojo/services/media_type_converters.cc
+++ b/media/mojo/services/media_type_converters.cc
@@ -419,9 +419,10 @@ media::interfaces::AudioDecoderConfigPtr TypeConverter<
config->channel_layout =
static_cast<media::interfaces::ChannelLayout>(input.channel_layout());
config->samples_per_second = input.samples_per_second();
- if (!input.extra_data().empty()) {
- std::vector<uint8_t> extra_data = input.extra_data();
- config->extra_data.Swap(&extra_data);
+ if (input.extra_data()) {
+ std::vector<uint8_t> data(input.extra_data(),
+ input.extra_data() + input.extra_data_size());
+ config->extra_data.Swap(&data);
}
config->seek_preroll_usec = input.seek_preroll().InMicroseconds();
config->codec_delay = input.codec_delay();
@@ -439,7 +440,10 @@ TypeConverter<media::AudioDecoderConfig,
static_cast<media::AudioCodec>(input->codec),
static_cast<media::SampleFormat>(input->sample_format),
static_cast<media::ChannelLayout>(input->channel_layout),
- input->samples_per_second, input->extra_data, input->is_encrypted,
+ input->samples_per_second,
+ input->extra_data.size() ? &input->extra_data.front() : NULL,
+ input->extra_data.size(),
+ input->is_encrypted,
base::TimeDelta::FromMicroseconds(input->seek_preroll_usec),
input->codec_delay);
return config;
@@ -461,7 +465,11 @@ media::interfaces::VideoDecoderConfigPtr TypeConverter<
config->coded_size = Size::From(input.coded_size());
config->visible_rect = Rect::From(input.visible_rect());
config->natural_size = Size::From(input.natural_size());
- config->extra_data = mojo::Array<uint8>::From(input.extra_data());
+ if (input.extra_data()) {
+ std::vector<uint8_t> data(input.extra_data(),
+ input.extra_data() + input.extra_data_size());
+ config->extra_data.Swap(&data);
+ }
config->is_encrypted = input.is_encrypted();
return config.Pass();
}
@@ -478,8 +486,9 @@ TypeConverter<media::VideoDecoderConfig,
static_cast<media::VideoPixelFormat>(input->format),
static_cast<media::ColorSpace>(input->color_space),
input->coded_size.To<gfx::Size>(), input->visible_rect.To<gfx::Rect>(),
- input->natural_size.To<gfx::Size>(), input->extra_data,
- input->is_encrypted);
+ input->natural_size.To<gfx::Size>(),
+ input->extra_data.size() ? &input->extra_data.front() : NULL,
+ input->extra_data.size(), input->is_encrypted);
return config;
}
diff --git a/media/mojo/services/media_type_converters_unittest.cc b/media/mojo/services/media_type_converters_unittest.cc
index 38559f3..54cd665 100644
--- a/media/mojo/services/media_type_converters_unittest.cc
+++ b/media/mojo/services/media_type_converters_unittest.cc
@@ -7,7 +7,6 @@
#include "media/base/audio_decoder_config.h"
#include "media/base/cdm_config.h"
#include "media/base/decoder_buffer.h"
-#include "media/base/media_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
@@ -122,23 +121,22 @@ TEST(MediaTypeConvertersTest, ConvertDecoderBuffer_EncryptedBuffer) {
// TODO(tim): Check other properties.
TEST(MediaTypeConvertersTest, ConvertAudioDecoderConfig_Normal) {
- const uint8_t kExtraData[] = "config extra data";
- const std::vector<uint8_t> kExtraDataVector(
- &kExtraData[0], &kExtraData[0] + arraysize(kExtraData));
-
+ const uint8 kExtraData[] = "config extra data";
+ const int kExtraDataSize = arraysize(kExtraData);
AudioDecoderConfig config;
config.Initialize(kCodecAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND, 48000,
- kExtraDataVector, false, base::TimeDelta(), 0);
+ reinterpret_cast<const uint8*>(&kExtraData), kExtraDataSize,
+ false, base::TimeDelta(), 0);
interfaces::AudioDecoderConfigPtr ptr(
interfaces::AudioDecoderConfig::From(config));
AudioDecoderConfig result(ptr.To<AudioDecoderConfig>());
EXPECT_TRUE(result.Matches(config));
}
-TEST(MediaTypeConvertersTest, ConvertAudioDecoderConfig_EmptyExtraData) {
+TEST(MediaTypeConvertersTest, ConvertAudioDecoderConfig_NullExtraData) {
AudioDecoderConfig config;
config.Initialize(kCodecAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND, 48000,
- EmptyExtraData(), false, base::TimeDelta(), 0);
+ NULL, 0, false, base::TimeDelta(), 0);
interfaces::AudioDecoderConfigPtr ptr(
interfaces::AudioDecoderConfig::From(config));
AudioDecoderConfig result(ptr.To<AudioDecoderConfig>());
@@ -148,7 +146,7 @@ TEST(MediaTypeConvertersTest, ConvertAudioDecoderConfig_EmptyExtraData) {
TEST(MediaTypeConvertersTest, ConvertAudioDecoderConfig_Encrypted) {
AudioDecoderConfig config;
config.Initialize(kCodecAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND, 48000,
- EmptyExtraData(),
+ NULL, 0,
true, // Is encrypted.
base::TimeDelta(), 0);
interfaces::AudioDecoderConfigPtr ptr(
diff --git a/media/renderers/audio_renderer_impl_unittest.cc b/media/renderers/audio_renderer_impl_unittest.cc
index 2367c42..9e9bf87 100644
--- a/media/renderers/audio_renderer_impl_unittest.cc
+++ b/media/renderers/audio_renderer_impl_unittest.cc
@@ -13,7 +13,6 @@
#include "media/base/audio_splicer.h"
#include "media/base/fake_audio_renderer_sink.h"
#include "media/base/gmock_callback_support.h"
-#include "media/base/media_util.h"
#include "media/base/mock_filters.h"
#include "media/base/test_helpers.h"
#include "media/renderers/audio_renderer_impl.h"
@@ -70,7 +69,8 @@ class AudioRendererImplTest : public ::testing::Test {
kSampleFormat,
kChannelLayout,
kInputSamplesPerSecond,
- EmptyExtraData(),
+ NULL,
+ 0,
false);
demuxer_stream_.set_audio_decoder_config(audio_config);