OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef MEDIA_BASE_ANDROID_TEST_DATA_FACTORY_H_ | |
6 #define MEDIA_BASE_ANDROID_TEST_DATA_FACTORY_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 #include <set> | |
11 #include <vector> | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/time/time.h" | |
14 #include "media/base/android/demuxer_stream_player_params.h" | |
15 | |
16 namespace media { | |
17 | |
18 // TestDataFactory is used by MediaCodecDecoder unit test and MediaCodecPlayer | |
19 // unit test to simulate the audio or video access unit stream. | |
20 class TestDataFactory { | |
21 public: | |
22 // These methods return corresponding demuxer configs. | |
23 static DemuxerConfigs CreateAudioConfigs(AudioCodec audio_codec, | |
24 base::TimeDelta duration); | |
25 static DemuxerConfigs CreateVideoConfigs(VideoCodec video_codec, | |
26 base::TimeDelta duration, | |
27 const gfx::Size& video_size); | |
28 | |
29 // Constructor calls |LoadPackets| to load packets from files. | |
30 // Parameters: | |
31 // file_name_template: the sprintf format string used to generate a file | |
32 // name for the packet in the form e.g. "h264-AxB-%d" | |
33 // The |%d| will be replaced by 0, 1, 2, 3. | |
34 // duration: after the last AU exceeds duration the factory generates EOS | |
35 // unit and stops. | |
36 // frame_period: PTS increment between units. | |
37 TestDataFactory(const char* file_name_template, | |
38 const base::TimeDelta duration, | |
39 const base::TimeDelta frame_period); | |
40 virtual ~TestDataFactory(); | |
41 | |
42 // Returns demuxer configuration for this factory. | |
43 virtual DemuxerConfigs GetConfigs() const = 0; | |
44 | |
45 // Populates next chunk and the corresponding delay and returns true if | |
46 // duration is not exceeded, otherwise returns false. | |
47 // Default implementation repeatedly uses |packet_| array in order 0-1-2-3 | |
48 // and monotonically increases timestamps from 0 to |duration_|. | |
49 // The first unit to exceed |duration_| becomes EOS. The delay is set to 0. | |
50 virtual bool CreateChunk(DemuxerData* chunk, base::TimeDelta* delay); | |
51 | |
52 // In starvation mode we do not add EOS at the end. | |
53 void SetStarvationMode(bool value) { starvation_mode_ = value; } | |
54 | |
55 // Resets the timestamp for the next access unit. | |
56 void SeekTo(const base::TimeDelta& seek_time); | |
57 | |
58 // Request that a chunk containing sole |kConfigChanged| unit is generated | |
59 // before the first true data chunk. | |
60 void RequestInitialConfigs(); | |
61 | |
62 void RequestConfigChange(base::TimeDelta config_position); | |
63 | |
64 // Returns the maximum PTS, taking into account possible modifications | |
65 // by subclasses. The SeekTo() resets this value. | |
66 base::TimeDelta last_pts() const { return last_pts_; } | |
67 | |
68 protected: | |
69 // Called by constructor to load packets from files referred by | |
70 // |file_name_template|. | |
71 virtual void LoadPackets(const char* file_name_template); | |
72 | |
73 // Used to modify the generated chunk by a subclass. | |
74 virtual void ModifyChunk(DemuxerData* chunk) {} | |
75 | |
76 base::TimeDelta duration_; | |
77 base::TimeDelta frame_period_; | |
78 | |
79 private: | |
80 typedef std::set<base::TimeDelta> PTSSet; | |
81 | |
82 // |left| is included in the interval, |right| is excluded. | |
83 // If |left| == |right|, the interval is empty and the method returns false. | |
84 bool HasReconfigForInterval(base::TimeDelta left, | |
85 base::TimeDelta right) const; | |
86 | |
87 void AddConfiguration(DemuxerData* chunk); | |
88 | |
89 std::vector<uint8_t> packet_[4]; | |
90 base::TimeDelta regular_pts_; // monotonically increasing PTS | |
91 base::TimeDelta chunk_begin_pts_; // beginning of chunk time interval | |
92 base::TimeDelta last_pts_; // subclass can modify PTS, maintain the last | |
93 PTSSet reconfigs_; // ConfigChange requests | |
94 size_t total_chunks_; // total number of chunks returned | |
95 bool starvation_mode_; // true means no EOS at the end | |
96 bool eos_reached_; // true if CreateChunk() returned EOS frame | |
97 }; | |
98 | |
99 } // namespace media | |
100 | |
101 #endif // MEDIA_BASE_ANDROID_TEST_DATA_FACTORY_H_ | |
OLD | NEW |