|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 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_FILTERS_AUDIO_FILE_READER_H_ | |
6 #define MEDIA_FILTERS_AUDIO_FILE_READER_H_ | |
7 | |
8 #include <vector> | |
9 #include "media/filters/ffmpeg_glue.h" | |
10 | |
11 struct AVCodec; | |
12 struct AVCodecContext; | |
13 struct AVFormatContext; | |
14 | |
15 namespace media { | |
16 | |
17 class FFmpegURLProtocol; | |
18 | |
19 class AudioFileReader { | |
20 public: | |
21 // Audio file data will be read using the given protocol. | |
22 // Optionally, NULL may be passed in and SetProtocal() can be called | |
23 // later on before Open() is called. | |
24 explicit AudioFileReader(FFmpegURLProtocol* protocol); | |
25 virtual ~AudioFileReader(); | |
26 | |
27 // SetProtocol() may be set before a call to Open(). | |
28 void SetProtocol(FFmpegURLProtocol* protocol) { protocol_ = protocol; } | |
29 | |
30 int Open(); | |
scherkus (not reviewing)
2010/12/09 17:35:40
what's the result of this operation?
it looks lik
Chris Rogers
2010/12/10 23:34:00
You're right, returning bool is better - switched
| |
31 void Close(); | |
32 | |
33 // After a call to Open(), reads |number_of_frames| into |audio_data|. | |
34 // |audio_data| must be of the same size as NumberOfChannels(). | |
35 // The audio data will be decoded as floating-point linear PCM with | |
36 // a nominal range of -1.0 -> +1.0. | |
37 // Returns 0 on success. | |
38 int Read(const std::vector<float*>& audio_data, size_t number_of_frames); | |
39 | |
40 size_t NumberOfChannels() const; | |
scherkus (not reviewing)
2010/12/09 17:35:40
these look like simple accessors and should be nam
Chris Rogers
2010/12/10 23:34:00
Done.
| |
41 double GetSampleRate() const; | |
42 double GetDuration() const; | |
43 size_t Length() const; | |
scherkus (not reviewing)
2010/12/09 17:35:40
what is length computing?
judging by the call per
Chris Rogers
2010/12/10 23:34:00
changed method name to number_of_frames()
On 2010
| |
44 | |
45 private: | |
46 FFmpegURLProtocol* protocol_; | |
47 AVFormatContext* format_context_; | |
48 AVCodecContext* codec_context_; | |
49 AVCodec* codec_; | |
50 | |
51 DISALLOW_COPY_AND_ASSIGN(AudioFileReader); | |
52 }; | |
53 | |
54 class InMemoryDataReader : public FFmpegURLProtocol { | |
55 public: | |
56 explicit InMemoryDataReader(const char* data, int64 size); | |
scherkus (not reviewing)
2010/12/09 17:35:40
no need for explicit
Chris Rogers
2010/12/10 23:34:00
Done.
| |
57 | |
58 virtual int Read(int size, uint8* data); | |
59 virtual bool GetPosition(int64* position_out); | |
60 virtual bool SetPosition(int64 position); | |
61 virtual bool GetSize(int64* size_out); | |
62 virtual bool IsStreaming(); | |
63 | |
64 private: | |
65 const char* data_; | |
66 int64 size_; | |
67 int64 position_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(InMemoryDataReader); | |
70 }; | |
71 | |
72 class InMemoryAudioFileReader : public AudioFileReader { | |
scherkus (not reviewing)
2010/12/09 17:35:40
will we ever have different AudioFileReaders?
I'm
Chris Rogers
2010/12/10 23:34:00
I've switched the code to use option (2). Strange
| |
73 public: | |
74 InMemoryAudioFileReader(const char* data, size_t data_size) | |
75 : AudioFileReader(NULL), | |
76 data_reader_(data, data_size) { | |
77 SetProtocol(&data_reader_); | |
78 } | |
79 | |
80 private: | |
81 InMemoryDataReader data_reader_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(InMemoryAudioFileReader); | |
84 }; | |
85 | |
86 } // namespace media | |
87 | |
88 #endif // MEDIA_FILTERS_AUDIO_FILE_READER_H_ | |
OLD | NEW |