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
{
15 FrameGeneratorForTest::FrameSpec::FrameSpec()
18 has_decrypt_config(false),
22 FrameGeneratorForTest::FrameSpec::~FrameSpec() {
25 FrameGeneratorForTest::FrameGeneratorForTest(
26 const std::vector
<FrameSpec
> frame_specs
)
27 : frame_specs_(frame_specs
),
29 total_buffer_size_(0) {
32 FrameGeneratorForTest::~FrameGeneratorForTest() {
35 bool FrameGeneratorForTest::HasDecoderConfig() const {
36 if (frame_idx_
>= frame_specs_
.size())
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_
];
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
));
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;
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
;
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
;
85 subsamples
.push_back(subsample
);
89 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
90 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf };
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
)),
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_
;
113 } // namespace chromecast