1 // Copyright 2015 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 "media/base/android/test_data_factory.h"
7 #include "base/strings/stringprintf.h"
8 #include "media/base/android/demuxer_stream_player_params.h"
9 #include "media/base/decoder_buffer.h"
10 #include "media/base/test_data_util.h"
14 DemuxerConfigs
TestDataFactory::CreateAudioConfigs(AudioCodec audio_codec
,
15 base::TimeDelta duration
) {
16 DemuxerConfigs configs
;
17 configs
.audio_codec
= audio_codec
;
18 configs
.audio_channels
= 2;
19 configs
.is_audio_encrypted
= false;
20 configs
.duration
= duration
;
22 switch (audio_codec
) {
24 configs
.audio_sampling_rate
= 44100;
25 scoped_refptr
<DecoderBuffer
> buffer
=
26 ReadTestDataFile("vorbis-extradata");
27 configs
.audio_extra_data
= std::vector
<uint8
>(
28 buffer
->data(), buffer
->data() + buffer
->data_size());
32 configs
.audio_sampling_rate
= 44100;
33 configs
.audio_extra_data
= {0x12, 0x10};
37 // Other codecs are not supported by this helper.
45 DemuxerConfigs
TestDataFactory::CreateVideoConfigs(
46 VideoCodec video_codec
,
47 base::TimeDelta duration
,
48 const gfx::Size
& video_size
) {
49 DemuxerConfigs configs
;
50 configs
.video_codec
= video_codec
;
51 configs
.video_size
= video_size
;
52 configs
.is_video_encrypted
= false;
53 configs
.duration
= duration
;
58 TestDataFactory::TestDataFactory(const char* file_name_template
,
59 base::TimeDelta duration
,
60 base::TimeDelta frame_period
)
61 : duration_(duration
),
62 frame_period_(frame_period
),
63 starvation_mode_(false) {
64 LoadPackets(file_name_template
);
67 TestDataFactory::~TestDataFactory() {}
69 bool TestDataFactory::CreateChunk(DemuxerData
* chunk
, base::TimeDelta
* delay
) {
73 *delay
= base::TimeDelta();
75 for (int i
= 0; i
< 4; ++i
) {
76 chunk
->access_units
.push_back(AccessUnit());
77 AccessUnit
& unit
= chunk
->access_units
.back();
78 unit
.status
= DemuxerStream::kOk
;
80 unit
.timestamp
= regular_pts_
;
81 regular_pts_
+= frame_period_
;
83 if (unit
.timestamp
> duration_
) {
87 unit
.is_end_of_stream
= true;
88 break; // EOS units have no data.
91 unit
.data
= packet_
[i
];
93 // Allow for modification by subclasses.
94 ModifyAccessUnit(i
, &unit
);
96 // Maintain last PTS. ModifyAccessUnit() can modify unit's PTS.
97 if (last_pts_
< unit
.timestamp
)
98 last_pts_
= unit
.timestamp
;
104 void TestDataFactory::SeekTo(const base::TimeDelta
& seek_time
) {
105 regular_pts_
= seek_time
;
106 last_pts_
= base::TimeDelta();
109 void TestDataFactory::LoadPackets(const char* file_name_template
) {
110 for (int i
= 0; i
< 4; ++i
) {
111 scoped_refptr
<DecoderBuffer
> buffer
=
112 ReadTestDataFile(base::StringPrintf(file_name_template
, i
));
113 packet_
[i
] = std::vector
<uint8
>(buffer
->data(),
114 buffer
->data() + buffer
->data_size());