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