[MediaRouter] Update MR-2-Extension's PostMessage to return boolean.
[chromium-blink-merge.git] / chromecast / media / cma / test / frame_generator_for_test.cc
blobf2ed98d0207b3d18520e4d1f0fa1682ed56b5043
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/media/cma/test/frame_generator_for_test.h"
7 #include "chromecast/media/cma/base/decoder_buffer_adapter.h"
8 #include "chromecast/media/cma/base/decoder_buffer_base.h"
9 #include "media/base/decoder_buffer.h"
10 #include "media/base/decrypt_config.h"
12 namespace chromecast {
13 namespace media {
15 FrameGeneratorForTest::FrameSpec::FrameSpec()
16 : has_config(false),
17 is_eos(false),
18 has_decrypt_config(false),
19 size(0) {
22 FrameGeneratorForTest::FrameSpec::~FrameSpec() {
25 FrameGeneratorForTest::FrameGeneratorForTest(
26 const std::vector<FrameSpec> frame_specs)
27 : frame_specs_(frame_specs),
28 frame_idx_(0),
29 total_buffer_size_(0) {
32 FrameGeneratorForTest::~FrameGeneratorForTest() {
35 bool FrameGeneratorForTest::HasDecoderConfig() const {
36 if (frame_idx_ >= frame_specs_.size())
37 return false;
39 return frame_specs_[frame_idx_].has_config;
42 scoped_refptr<DecoderBufferBase> FrameGeneratorForTest::Generate() {
43 if (frame_idx_ >= frame_specs_.size())
44 return scoped_refptr<DecoderBufferBase>();
46 const FrameSpec& frame_spec = frame_specs_[frame_idx_];
47 frame_idx_++;
49 if (frame_spec.is_eos) {
50 return scoped_refptr<DecoderBufferBase>(
51 new DecoderBufferAdapter(::media::DecoderBuffer::CreateEOSBuffer()));
54 scoped_refptr< ::media::DecoderBuffer> buffer(
55 new ::media::DecoderBuffer(frame_spec.size));
57 // Timestamp.
58 buffer->set_timestamp(frame_spec.timestamp);
60 // Generate the frame data.
61 for (size_t k = 0; k < frame_spec.size; k++) {
62 buffer->writable_data()[k] = total_buffer_size_ & 0xff;
63 total_buffer_size_++;
66 // Generate the decrypt configuration.
67 if (frame_spec.has_decrypt_config) {
68 uint32 frame_size = buffer->data_size();
69 uint32 chunk_size = 1;
70 std::vector< ::media::SubsampleEntry> subsamples;
71 while (frame_size > 0) {
72 ::media::SubsampleEntry subsample;
73 subsample.clear_bytes = chunk_size;
74 if (subsample.clear_bytes > frame_size)
75 subsample.clear_bytes = frame_size;
76 frame_size -= subsample.clear_bytes;
77 chunk_size <<= 1;
79 subsample.cypher_bytes = chunk_size;
80 if (subsample.cypher_bytes > frame_size)
81 subsample.cypher_bytes = frame_size;
82 frame_size -= subsample.cypher_bytes;
83 chunk_size <<= 1;
85 subsamples.push_back(subsample);
88 char key_id[] = {
89 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
90 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf };
92 char iv[] = {
93 0x0, 0x2, 0x1, 0x3, 0x5, 0x4, 0x7, 0x6,
94 0x9, 0x8, 0xb, 0xa, 0xd, 0xc, 0xf, 0xe };
96 scoped_ptr< ::media::DecryptConfig> decrypt_config(
97 new ::media::DecryptConfig(
98 std::string(key_id, arraysize(key_id)),
99 std::string(iv, arraysize(iv)),
100 subsamples));
101 buffer->set_decrypt_config(decrypt_config.Pass());
104 return scoped_refptr<DecoderBufferBase>(new DecoderBufferAdapter(buffer));
107 size_t FrameGeneratorForTest::RemainingFrameCount() const {
108 size_t count = frame_specs_.size() - frame_idx_;
109 return count;
112 } // namespace media
113 } // namespace chromecast