Roll src/third_party/WebKit d10c917:a1123a1 (svn 198729:198730)
[chromium-blink-merge.git] / media / base / android / test_data_factory.h
blobb186d75e27662781babf5e79509238ab0a6a3cd0
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 <vector>
10 #include "base/memory/ref_counted.h"
11 #include "base/time/time.h"
12 #include "media/base/android/demuxer_stream_player_params.h"
14 namespace media {
16 // TestDataFactory is used by MediaCodecDecoder unit test and MediaCodecPlayer
17 // unit test to simulate the audio or video access unit stream.
18 class TestDataFactory {
19 public:
20 // These methods return corresponding demuxer configs.
21 static DemuxerConfigs CreateAudioConfigs(AudioCodec audio_codec,
22 const base::TimeDelta& duration);
23 static DemuxerConfigs CreateVideoConfigs(VideoCodec video_codec,
24 const base::TimeDelta& duration,
25 const gfx::Size& video_size);
27 // Constructor calls |LoadPackets| to load packets from files.
28 // Parameters:
29 // file_name_template: the sprintf format string used to generate a file
30 // name for the packet in the form e.g. "h264-AxB-%d"
31 // The |%d| will be replaced by 0, 1, 2, 3.
32 // duration: after the last AU exceeds duration the factory generates EOS
33 // unit and stops.
34 // frame_period: PTS increment between units.
35 TestDataFactory(const char* file_name_template,
36 const base::TimeDelta& duration,
37 const base::TimeDelta& frame_period);
38 virtual ~TestDataFactory();
40 // Returns demuxer configuration for this factory.
41 virtual DemuxerConfigs GetConfigs() const = 0;
43 // Populates next chunk and the corresponding delay and returns true if
44 // duration is not exceeded, otherwise returns false.
45 // Default implementation repeatedly uses |packet_| array in order 0-1-2-3
46 // and monotonically increases timestamps from 0 to |duration_|.
47 // The first unit to exceed |duration_| becomes EOS. The delay is set to 0.
48 virtual bool CreateChunk(DemuxerData* chunk, base::TimeDelta* delay);
50 // In starvation mode we do not add EOS at the end.
51 void SetStarvationMode(bool value) { starvation_mode_ = value; }
53 base::TimeDelta last_pts() const { return last_pts_; }
55 protected:
56 // Called by constructor to load packets from files referred by
57 // |file_name_template|.
58 virtual void LoadPackets(const char* file_name_template);
60 // Used to modify the generated access unit by a subclass.
61 virtual void ModifyAccessUnit(int index_in_chunk, AccessUnit* unit) {}
63 base::TimeDelta duration_;
64 base::TimeDelta frame_period_;
65 std::vector<uint8_t> packet_[4];
66 base::TimeDelta regular_pts_; // monotonically increasing PTS
67 base::TimeDelta last_pts_; // subclass can modify PTS, maintains the last
68 bool starvation_mode_; // true means no EOS at the end
71 } // namespace media
73 #endif // MEDIA_BASE_ANDROID_TEST_DATA_FACTORY_H_