OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this | |
2 // source code is governed by a BSD-style license that can be found in the | |
3 // LICENSE file. | |
4 | |
5 #ifndef MEDIA_TOOLS_OMX_TEST_FILE_READER_UTIL_H_ | |
6 #define MEDIA_TOOLS_OMX_TEST_FILE_READER_UTIL_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/file_path.h" | |
12 #include "base/memory/scoped_handle.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 | |
15 struct AVCodecContext; | |
16 struct AVFormatContext; | |
17 | |
18 namespace media { | |
19 | |
20 class BitstreamConverter; | |
21 | |
22 // A class to help reading and parsing input file for use in omx_test. | |
23 class FileReader { | |
24 public: | |
25 virtual ~FileReader() {} | |
26 | |
27 // Initialize FileReader object, returns true if successful. | |
28 virtual bool Initialize() = 0; | |
29 | |
30 // Read the file into |output|, and output the number of bytes read to | |
31 // |size|. | |
32 virtual void Read(uint8** output, int* size) = 0; | |
33 }; | |
34 | |
35 class BasicFileReader : public FileReader { | |
36 public: | |
37 explicit BasicFileReader(const FilePath& path); | |
38 virtual bool Initialize(); | |
39 virtual void Read(uint8** output, int* size) = 0; | |
40 | |
41 protected: | |
42 FILE* file() const { return file_.get(); } | |
43 | |
44 private: | |
45 FilePath path_; | |
46 ScopedStdioHandle file_; | |
47 | |
48 DISALLOW_COPY_AND_ASSIGN(BasicFileReader); | |
49 }; | |
50 | |
51 class YuvFileReader : public BasicFileReader { | |
52 public: | |
53 // Construct a YUV file reader with looping and color space conversion | |
54 // ability. |loop_count| specifies the number of times the input file | |
55 // is read. If |enable_csc| is true, input in YV420 is converted to | |
56 // NV21. | |
57 // TODO(jiesun): Make color space more generic not a hard coded color | |
58 // space conversion. | |
59 YuvFileReader(const FilePath& path, | |
60 int width, | |
61 int height, | |
62 int loop_count, | |
63 bool output_nv21); | |
64 virtual ~YuvFileReader(); | |
65 | |
66 virtual void Read(uint8** output, int* size); | |
67 | |
68 private: | |
69 int width_; | |
70 int height_; | |
71 int loop_count_; | |
72 bool output_nv21_; | |
73 scoped_array<uint8> csc_buf_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(YuvFileReader); | |
76 }; | |
77 | |
78 class BlockFileReader : public BasicFileReader { | |
79 public: | |
80 BlockFileReader(const FilePath& path, | |
81 int block_size); | |
82 virtual void Read(uint8** output, int* size); | |
83 | |
84 private: | |
85 int block_size_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(BlockFileReader); | |
88 }; | |
89 | |
90 class FFmpegFileReader : public FileReader { | |
91 public: | |
92 explicit FFmpegFileReader(const FilePath& path); | |
93 virtual ~FFmpegFileReader(); | |
94 virtual bool Initialize(); | |
95 virtual void Read(uint8** output, int* size); | |
96 | |
97 private: | |
98 FilePath path_; | |
99 AVFormatContext* format_context_; | |
100 AVCodecContext* codec_context_; | |
101 int target_stream_; | |
102 scoped_ptr<media::BitstreamConverter> converter_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(FFmpegFileReader); | |
105 }; | |
106 | |
107 class H264FileReader : public BasicFileReader { | |
108 public: | |
109 explicit H264FileReader(const FilePath& path); | |
110 virtual ~H264FileReader(); | |
111 virtual void Read(uint8** output, int* size); | |
112 | |
113 private: | |
114 scoped_array<uint8> read_buf_; | |
115 int current_; | |
116 int used_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(H264FileReader); | |
119 }; | |
120 | |
121 } // namespace media | |
122 | |
123 #endif // MEDIA_TOOLS_OMX_TEST_FILE_READER_UTIL_H_ | |
OLD | NEW |