summaryrefslogtreecommitdiffstats
path: root/media/tools/omx_test/file_reader_util.h
blob: c1c0b2db30547357366c47e05e0aba987ee11091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2010 The Chromium Authors. All rights reserved.  Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.

#ifndef MEDIA_TOOLS_OMX_TEST_FILE_READER_UTIL_H_
#define MEDIA_TOOLS_OMX_TEST_FILE_READER_UTIL_H_

#include <string>

#include "base/basictypes.h"
#include "base/scoped_handle.h"
#include "base/scoped_ptr.h"

struct AVCodecContext;
struct AVFormatContext;

namespace media {

class BitstreamConverter;

// A class to help reading and parsing input file for use in omx_test.
class FileReader {
 public:
  virtual ~FileReader() {}

  // Initialize FileReader object, returns true if successful.
  virtual bool Initialize() = 0;

  // Read the file into |output|, and output the number of bytes read to
  // |size|.
  virtual void Read(uint8** output, int* size) = 0;
};

class BasicFileReader : public FileReader {
 public:
  explicit BasicFileReader(const char* filename);
  virtual bool Initialize();
  virtual void Read(uint8** output, int* size) = 0;

 protected:
  FILE* file() const { return file_.get(); }

 private:
  std::string filename_;
  ScopedStdioHandle file_;

  DISALLOW_COPY_AND_ASSIGN(BasicFileReader);
};

class YuvFileReader : public BasicFileReader {
 public:
  // Construct a YUV file reader with looping and color space conversion
  // ability. |loop_count| specifies the number of times the input file
  // is read. If |enable_csc| is true, input in YV420 is converted to
  // NV21.
  // TODO(jiesun): Make color space more generic not a hard coded color
  // space conversion.
  YuvFileReader(const char* filename,
                int width,
                int height,
                int loop_count,
                bool output_nv21);
  virtual void Read(uint8** output, int* size);

 private:
  int width_;
  int height_;
  int loop_count_;
  bool output_nv21_;
  scoped_array<uint8> csc_buf_;

  DISALLOW_COPY_AND_ASSIGN(YuvFileReader);
};

class BlockFileReader : public BasicFileReader {
 public:
  BlockFileReader(const char* filename,
                  int block_size);
  virtual void Read(uint8** output, int* size);

 private:
  int block_size_;

  DISALLOW_COPY_AND_ASSIGN(BlockFileReader);
};

class FFmpegFileReader : public FileReader {
 public:
  explicit FFmpegFileReader(const char* filename);
  virtual ~FFmpegFileReader();
  virtual bool Initialize();
  virtual void Read(uint8** output, int* size);

 private:
  std::string filename_;
  AVFormatContext* format_context_;
  AVCodecContext* codec_context_;
  int target_stream_;
  scoped_ptr<media::BitstreamConverter> converter_;

  DISALLOW_COPY_AND_ASSIGN(FFmpegFileReader);
};

class H264FileReader : public BasicFileReader {
 public:
  explicit H264FileReader(const char* filename);
  virtual void Read(uint8** output, int* size);

 private:
  scoped_array<uint8> read_buf_;
  int current_;
  int used_;

  DISALLOW_COPY_AND_ASSIGN(H264FileReader);
};

}  // namespace media

#endif  // MEDIA_TOOLS_OMX_TEST_FILE_READER_UTIL_H_