diff options
Diffstat (limited to 'chromecast/media/cma')
11 files changed, 166 insertions, 21 deletions
diff --git a/chromecast/media/cma/backend/audio_video_pipeline_device_unittest.cc b/chromecast/media/cma/backend/audio_video_pipeline_device_unittest.cc index 7fd2d1d..18de287 100644 --- a/chromecast/media/cma/backend/audio_video_pipeline_device_unittest.cc +++ b/chromecast/media/cma/backend/audio_video_pipeline_device_unittest.cc @@ -35,6 +35,7 @@ #include "media/base/audio_decoder_config.h" #include "media/base/audio_timestamp_helper.h" #include "media/base/decoder_buffer.h" +#include "media/base/encryption_scheme.h" #include "media/base/video_decoder_config.h" #include "testing/gtest/include/gtest/gtest.h" @@ -68,7 +69,7 @@ VideoConfig DefaultVideoConfig() { default_config.codec = kCodecH264; default_config.profile = kH264Main; default_config.additional_config = nullptr; - default_config.is_encrypted = false; + default_config.encryption_scheme = Unencrypted(); return default_config; } @@ -564,7 +565,7 @@ scoped_ptr<BufferFeeder> BufferFeeder::LoadVideo(MediaPipelineBackend* backend, video_config.codec = kCodecH264; video_config.profile = kH264Main; video_config.additional_config = nullptr; - video_config.is_encrypted = false; + video_config.encryption_scheme = Unencrypted(); } else { base::FilePath file_path = GetTestDataFilePath(filename); DemuxResult demux_result = FFmpegDemuxForTest(file_path, false /* audio */); diff --git a/chromecast/media/cma/base/decoder_config_adapter.cc b/chromecast/media/cma/base/decoder_config_adapter.cc index 3a8ab39..24e8b41 100644 --- a/chromecast/media/cma/base/decoder_config_adapter.cc +++ b/chromecast/media/cma/base/decoder_config_adapter.cc @@ -85,7 +85,7 @@ VideoCodec ToVideoCodec(const ::media::VideoCodec video_codec) { // Converts ::media::VideoCodecProfile to chromecast::media::VideoProfile. VideoProfile ToVideoProfile(const ::media::VideoCodecProfile codec_profile) { - switch(codec_profile) { + switch (codec_profile) { case ::media::H264PROFILE_BASELINE: return kH264Baseline; case ::media::H264PROFILE_MAIN: @@ -183,6 +183,62 @@ VideoProfile ToVideoProfile(const ::media::VideoCodecProfile codec_profile) { } } +::media::EncryptionScheme::CipherMode ToMediaCipherMode( + EncryptionScheme::CipherMode mode) { + switch (mode) { + case EncryptionScheme::CIPHER_MODE_UNENCRYPTED: + return ::media::EncryptionScheme::CIPHER_MODE_UNENCRYPTED; + case EncryptionScheme::CIPHER_MODE_AES_CTR: + return ::media::EncryptionScheme::CIPHER_MODE_AES_CTR; + case EncryptionScheme::CIPHER_MODE_AES_CBC: + return ::media::EncryptionScheme::CIPHER_MODE_AES_CBC; + default: + NOTREACHED(); + return ::media::EncryptionScheme::CIPHER_MODE_UNENCRYPTED; + } +} + +EncryptionScheme::CipherMode ToCipherMode( + ::media::EncryptionScheme::CipherMode mode) { + switch (mode) { + case ::media::EncryptionScheme::CIPHER_MODE_UNENCRYPTED: + return EncryptionScheme::CIPHER_MODE_UNENCRYPTED; + case ::media::EncryptionScheme::CIPHER_MODE_AES_CTR: + return EncryptionScheme::CIPHER_MODE_AES_CTR; + case ::media::EncryptionScheme::CIPHER_MODE_AES_CBC: + return EncryptionScheme::CIPHER_MODE_AES_CBC; + default: + NOTREACHED(); + return EncryptionScheme::CIPHER_MODE_UNENCRYPTED; + } +} + +EncryptionScheme::Pattern ToPatternSpec( + const ::media::EncryptionScheme::Pattern& pattern) { + return EncryptionScheme::Pattern( + pattern.encrypt_blocks(), pattern.skip_blocks()); +} + +::media::EncryptionScheme::Pattern ToMediaPatternSpec( + const EncryptionScheme::Pattern& pattern) { + return ::media::EncryptionScheme::Pattern( + pattern.encrypt_blocks, pattern.skip_blocks); +} + +EncryptionScheme ToEncryptionScheme( + const ::media::EncryptionScheme& scheme) { + return EncryptionScheme( + ToCipherMode(scheme.mode()), + ToPatternSpec(scheme.pattern())); +} + +::media::EncryptionScheme ToMediaEncryptionScheme( + const EncryptionScheme& scheme) { + return ::media::EncryptionScheme( + ToMediaCipherMode(scheme.mode), + ToMediaPatternSpec(scheme.pattern)); +} + } // namespace // static @@ -201,7 +257,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(); - audio_config.is_encrypted = config.is_encrypted(); + audio_config.encryption_scheme = ToEncryptionScheme( + config.encryption_scheme()); return audio_config; } @@ -212,7 +269,8 @@ AudioConfig DecoderConfigAdapter::ToCastAudioConfig( ToMediaAudioCodec(config.codec), ToMediaSampleFormat(config.sample_format), ToMediaChannelLayout(config.channel_number), config.samples_per_second, - config.extra_data, config.is_encrypted); + config.extra_data, + ToMediaEncryptionScheme(config.encryption_scheme)); } // static @@ -228,7 +286,8 @@ VideoConfig DecoderConfigAdapter::ToCastVideoConfig( video_config.codec = ToVideoCodec(config.codec()); video_config.profile = ToVideoProfile(config.profile()); video_config.extra_data = config.extra_data(); - video_config.is_encrypted = config.is_encrypted(); + video_config.encryption_scheme = ToEncryptionScheme( + config.encryption_scheme()); return video_config; } diff --git a/chromecast/media/cma/base/demuxer_stream_for_test.cc b/chromecast/media/cma/base/demuxer_stream_for_test.cc index 9942545..32ee27b 100644 --- a/chromecast/media/cma/base/demuxer_stream_for_test.cc +++ b/chromecast/media/cma/base/demuxer_stream_for_test.cc @@ -63,7 +63,7 @@ void DemuxerStreamForTest::Read(const ReadCB& read_cb) { visible_rect, natural_size, ::media::EmptyExtraData(), - false); + ::media::Unencrypted()); } ::media::DemuxerStream::Type DemuxerStreamForTest::type() const { diff --git a/chromecast/media/cma/ipc_streamer/BUILD.gn b/chromecast/media/cma/ipc_streamer/BUILD.gn index a3429d6..7d25f45 100644 --- a/chromecast/media/cma/ipc_streamer/BUILD.gn +++ b/chromecast/media/cma/ipc_streamer/BUILD.gn @@ -14,6 +14,8 @@ source_set("ipc_streamer") { "decoder_buffer_base_marshaller.h", "decrypt_config_marshaller.cc", "decrypt_config_marshaller.h", + "encryption_scheme_marshaller.cc", + "encryption_scheme_marshaller.h", "video_decoder_config_marshaller.cc", "video_decoder_config_marshaller.h", ] 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 2798c6b..031571a 100644 --- a/chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.cc +++ b/chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "chromecast/media/cma/ipc/media_message.h" +#include "chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.h" #include "media/base/audio_decoder_config.h" namespace chromecast { @@ -27,7 +28,7 @@ void AudioDecoderConfigMarshaller::Write( CHECK(msg->WritePod(config.channel_layout())); CHECK(msg->WritePod(config.samples_per_second())); CHECK(msg->WritePod(config.sample_format())); - CHECK(msg->WritePod(config.is_encrypted())); + EncryptionSchemeMarshaller::Write(config.encryption_scheme(), msg); CHECK(msg->WritePod(config.extra_data().size())); if (!config.extra_data().empty()) CHECK(msg->WriteBuffer(&config.extra_data()[0], @@ -41,15 +42,15 @@ void AudioDecoderConfigMarshaller::Write( ::media::SampleFormat sample_format; ::media::ChannelLayout channel_layout; int samples_per_second; - bool is_encrypted; size_t extra_data_size; std::vector<uint8_t> extra_data; + ::media::EncryptionScheme encryption_scheme; CHECK(msg->ReadPod(&codec)); CHECK(msg->ReadPod(&channel_layout)); CHECK(msg->ReadPod(&samples_per_second)); CHECK(msg->ReadPod(&sample_format)); - CHECK(msg->ReadPod(&is_encrypted)); + encryption_scheme = EncryptionSchemeMarshaller::Read(msg); CHECK(msg->ReadPod(&extra_data_size)); CHECK_GE(codec, ::media::kUnknownAudioCodec); @@ -67,7 +68,7 @@ void AudioDecoderConfigMarshaller::Write( return ::media::AudioDecoderConfig( codec, sample_format, channel_layout, samples_per_second, - extra_data, is_encrypted); + extra_data, encryption_scheme); } } // namespace media diff --git a/chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.cc b/chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.cc new file mode 100644 index 0000000..a88cfc5 --- /dev/null +++ b/chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.cc @@ -0,0 +1,54 @@ +// 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 "chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.h" + +#include <stdint.h> + +#include "base/logging.h" +#include "chromecast/media/cma/ipc/media_message.h" + +namespace chromecast { +namespace media { + +namespace { + +class PatternSpecMarshaller { + public: + static void Write(const ::media::EncryptionScheme::Pattern& pattern, + MediaMessage* msg) { + CHECK(msg->WritePod(pattern.encrypt_blocks())); + CHECK(msg->WritePod(pattern.skip_blocks())); + } + + static ::media::EncryptionScheme::Pattern Read(MediaMessage* msg) { + uint32_t encrypt_blocks; + uint32_t skip_blocks; + CHECK(msg->ReadPod(&encrypt_blocks)); + CHECK(msg->ReadPod(&skip_blocks)); + return ::media::EncryptionScheme::Pattern(encrypt_blocks, skip_blocks); + } +}; + +} // namespace + +// static +void EncryptionSchemeMarshaller::Write( + const ::media::EncryptionScheme& encryption_scheme, + MediaMessage* msg) { + CHECK(msg->WritePod(encryption_scheme.mode())); + PatternSpecMarshaller::Write(encryption_scheme.pattern(), msg); +} + +// static +::media::EncryptionScheme EncryptionSchemeMarshaller::Read(MediaMessage* msg) { + ::media::EncryptionScheme::CipherMode mode; + ::media::EncryptionScheme::Pattern pattern; + CHECK(msg->ReadPod(&mode)); + pattern = PatternSpecMarshaller::Read(msg); + return ::media::EncryptionScheme(mode, pattern); +} + +} // namespace media +} // namespace chromecast diff --git a/chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.h b/chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.h new file mode 100644 index 0000000..0b3371b --- /dev/null +++ b/chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.h @@ -0,0 +1,27 @@ +// 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 CHROMECAST_MEDIA_CMA_IPC_STREAMER_ENCRYPTION_SCHEME_MARSHALLER_H_ +#define CHROMECAST_MEDIA_CMA_IPC_STREAMER_ENCRYPTION_SCHEME_MARSHALLER_H_ + +#include "media/base/encryption_scheme.h" + +namespace chromecast { +namespace media { +class MediaMessage; + +class EncryptionSchemeMarshaller { + public: + // Writes the serialized structure of |encryption_scheme| into |msg|. + static void Write( + const ::media::EncryptionScheme& encryption_scheme, MediaMessage* msg); + + // Returns an EncryptionScheme from its serialized structure. + static ::media::EncryptionScheme Read(MediaMessage* msg); +}; + +} // namespace media +} // namespace chromecast + +#endif // CHROMECAST_MEDIA_CMA_IPC_STREAMER_ENCRYPTION_SCHEME_MARSHALLER_H_ 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 b2e9aaa..a471eb6 100644 --- a/chromecast/media/cma/ipc_streamer/video_decoder_config_marshaller.cc +++ b/chromecast/media/cma/ipc_streamer/video_decoder_config_marshaller.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "chromecast/media/cma/ipc/media_message.h" +#include "chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.h" #include "media/base/video_decoder_config.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" @@ -67,7 +68,7 @@ void VideoDecoderConfigMarshaller::Write( SizeMarshaller::Write(config.coded_size(), msg); RectMarshaller::Write(config.visible_rect(), msg); SizeMarshaller::Write(config.natural_size(), msg); - CHECK(msg->WritePod(config.is_encrypted())); + EncryptionSchemeMarshaller::Write(config.encryption_scheme(), msg); CHECK(msg->WritePod(config.extra_data().size())); if (!config.extra_data().empty()) CHECK(msg->WriteBuffer(&config.extra_data()[0], @@ -84,8 +85,8 @@ void VideoDecoderConfigMarshaller::Write( gfx::Size coded_size; gfx::Rect visible_rect; gfx::Size natural_size; - bool is_encrypted; size_t extra_data_size; + ::media::EncryptionScheme encryption_scheme; std::vector<uint8_t> extra_data; CHECK(msg->ReadPod(&codec)); @@ -95,7 +96,7 @@ void VideoDecoderConfigMarshaller::Write( coded_size = SizeMarshaller::Read(msg); visible_rect = RectMarshaller::Read(msg); natural_size = SizeMarshaller::Read(msg); - CHECK(msg->ReadPod(&is_encrypted)); + encryption_scheme = EncryptionSchemeMarshaller::Read(msg); CHECK(msg->ReadPod(&extra_data_size)); CHECK_GE(codec, ::media::kUnknownVideoCodec); @@ -115,7 +116,7 @@ void VideoDecoderConfigMarshaller::Write( return ::media::VideoDecoderConfig( codec, profile, format, color_space, coded_size, visible_rect, natural_size, - extra_data, is_encrypted); + extra_data, encryption_scheme); } } // namespace media diff --git a/chromecast/media/cma/pipeline/audio_decoder_software_wrapper.cc b/chromecast/media/cma/pipeline/audio_decoder_software_wrapper.cc index 4b15bcc..a1cdf95 100644 --- a/chromecast/media/cma/pipeline/audio_decoder_software_wrapper.cc +++ b/chromecast/media/cma/pipeline/audio_decoder_software_wrapper.cc @@ -59,7 +59,7 @@ bool AudioDecoderSoftwareWrapper::SetConfig(const AudioConfig& config) { return true; } - if (config.is_encrypted || !CreateSoftwareDecoder(config)) + if (config.is_encrypted() || !CreateSoftwareDecoder(config)) return false; output_config_.codec = media::kCodecPCM; @@ -67,7 +67,7 @@ bool AudioDecoderSoftwareWrapper::SetConfig(const AudioConfig& config) { output_config_.channel_number = 2; output_config_.bytes_per_channel = 2; output_config_.samples_per_second = config.samples_per_second; - output_config_.is_encrypted = false; + output_config_.encryption_scheme = Unencrypted(); return backend_decoder_->SetConfig(output_config_); } 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 bd747dd..eba1961 100644 --- a/chromecast/media/cma/pipeline/audio_video_pipeline_impl_unittest.cc +++ b/chromecast/media/cma/pipeline/audio_video_pipeline_impl_unittest.cc @@ -66,7 +66,7 @@ class AudioVideoPipelineImplTest ::media::AudioDecoderConfig audio_config( ::media::kCodecMP3, ::media::kSampleFormatS16, ::media::CHANNEL_LAYOUT_STEREO, 44100, ::media::EmptyExtraData(), - false); + ::media::Unencrypted()); AvPipelineClient client; client.eos_cb = base::Bind(&AudioVideoPipelineImplTest::OnEos, base::Unretained(this), STREAM_AUDIO); @@ -80,7 +80,7 @@ class AudioVideoPipelineImplTest ::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)); + ::media::EmptyExtraData(), ::media::Unencrypted())); VideoPipelineClient client; client.av_pipeline_client.eos_cb = base::Bind(&AudioVideoPipelineImplTest::OnEos, base::Unretained(this), diff --git a/chromecast/media/cma/test/mock_frame_provider.cc b/chromecast/media/cma/test/mock_frame_provider.cc index fdab889..16d6393 100644 --- a/chromecast/media/cma/test/mock_frame_provider.cc +++ b/chromecast/media/cma/test/mock_frame_provider.cc @@ -82,7 +82,7 @@ void MockFrameProvider::DoRead(const ReadCB& read_cb) { ::media::kCodecH264, ::media::VIDEO_CODEC_PROFILE_UNKNOWN, ::media::PIXEL_FORMAT_YV12, ::media::COLOR_SPACE_UNSPECIFIED, coded_size, visible_rect, natural_size, ::media::EmptyExtraData(), - false); + ::media::Unencrypted()); audio_config = ::media::AudioDecoderConfig( ::media::kCodecAAC, @@ -90,7 +90,7 @@ void MockFrameProvider::DoRead(const ReadCB& read_cb) { ::media::CHANNEL_LAYOUT_STEREO, 44100, ::media::EmptyExtraData(), - false); + ::media::Unencrypted()); } read_cb.Run(buffer, audio_config, video_config); |