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. 4 5 #ifndef MEDIA_FORMATS_COMMON_STREAM_PARSER_TEST_BASE_H_ 6 #define MEDIA_FORMATS_COMMON_STREAM_PARSER_TEST_BASE_H_ 7 8 #include "base/memory/scoped_ptr.h" 9 #include "media/base/audio_decoder_config.h" 10 #include "media/base/stream_parser.h" 11 #include "media/base/stream_parser_buffer.h" 12 #include "media/base/text_track_config.h" 13 #include "media/base/video_decoder_config.h" 14 15 namespace media { 16 17 // Test helper for verifying StreamParser behavior. 18 class StreamParserTestBase { 19 public: 20 explicit StreamParserTestBase(scoped_ptr<StreamParser> stream_parser); 21 virtual ~StreamParserTestBase(); 22 23 protected: 24 // Chunks a given parser appropriate file. Appends |append_bytes| at a time 25 // until the file is exhausted. Returns a coded string representing the 26 // segments and timestamps of the extracted frames. 27 // 28 // The start of each media segment is designated by "NewSegment", similarly 29 // the end of each segment by "EndOfSegment". Segments end when one or more 30 // frames are parsed from an append. If the append contains a partial frame 31 // the segment will continue into the next append. 32 // 33 // Parsed frame(s) are represented as "{ xxK yyK zzK }" Where xx, yy, and zz 34 // are the timestamps in milliseconds of each parsed frame. For example: 35 // 36 // "NewSegment{ 0K 23K 46K }EndOfSegment" 37 // "NewSegment{ 0K }{ 23K }{ 46K }EndOfSegment" 38 // "NewSegment{ 0K }{ 23K }EndOfSegmentNewSegment{ 46K }EndOfSegment" 39 // 40 std::string ParseFile(const std::string& filename, int append_bytes); 41 42 // Similar to ParseFile() except parses the given |data| in a single append of 43 // size |length|. 44 std::string ParseData(const uint8* data, size_t length); 45 46 // The last AudioDecoderConfig handed to OnNewConfig(). 47 const AudioDecoderConfig& last_audio_config() const { 48 return last_audio_config_; 49 } 50 51 private: 52 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size); 53 void OnInitDone(bool success, const StreamParser::InitParameters& params); 54 bool OnNewConfig(const AudioDecoderConfig& audio_config, 55 const VideoDecoderConfig& video_config, 56 const StreamParser::TextTrackConfigMap& text_config); 57 bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, 58 const StreamParser::BufferQueue& video_buffers, 59 const StreamParser::TextBufferQueueMap& text_map); 60 void OnKeyNeeded(const std::string& type, 61 const std::vector<uint8>& init_data); 62 void OnNewSegment(); 63 void OnEndOfSegment(); 64 65 scoped_ptr<StreamParser> parser_; 66 std::stringstream results_stream_; 67 AudioDecoderConfig last_audio_config_; 68 69 DISALLOW_COPY_AND_ASSIGN(StreamParserTestBase); 70 }; 71 72 } // namespace media 73 74 #endif // MEDIA_FORMATS_COMMON_STREAM_PARSER_TEST_BASE_H_ 75