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 base { class TimeDelta; } |
| 16 |
| 17 namespace media { |
| 18 |
| 19 class FFmpegURLProtocol; |
| 20 |
| 21 class AudioFileReader { |
| 22 public: |
| 23 // Audio file data will be read using the given protocol. |
| 24 // The AudioFileReader does not take ownership of |protocol| and |
| 25 // simply maintains a weak reference to it. |
| 26 explicit AudioFileReader(FFmpegURLProtocol* protocol); |
| 27 virtual ~AudioFileReader(); |
| 28 |
| 29 // Open() reads the audio data format so that the sample_rate(), |
| 30 // channels(), duration(), and number_of_frames() methods can be called. |
| 31 // It returns |true| on success. |
| 32 bool Open(); |
| 33 void Close(); |
| 34 |
| 35 // After a call to Open(), reads |number_of_frames| into |audio_data|. |
| 36 // |audio_data| must be of the same size as channels(). |
| 37 // The audio data will be decoded as floating-point linear PCM with |
| 38 // a nominal range of -1.0 -> +1.0. |
| 39 // Returns |true| on success. |
| 40 bool Read(const std::vector<float*>& audio_data, size_t number_of_frames); |
| 41 |
| 42 // These methods can be called once Open() has been called. |
| 43 int channels() const; |
| 44 int sample_rate() const; |
| 45 base::TimeDelta duration() const; |
| 46 int64 number_of_frames() const; |
| 47 |
| 48 private: |
| 49 FFmpegURLProtocol* protocol_; |
| 50 AVFormatContext* format_context_; |
| 51 AVCodecContext* codec_context_; |
| 52 AVCodec* codec_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(AudioFileReader); |
| 55 }; |
| 56 |
| 57 class InMemoryDataReader : public FFmpegURLProtocol { |
| 58 public: |
| 59 // Ownership of |data| is not taken, instead it simply maintains |
| 60 // a weak reference. |
| 61 InMemoryDataReader(const char* data, int64 size); |
| 62 |
| 63 virtual int Read(int size, uint8* data); |
| 64 virtual bool GetPosition(int64* position_out); |
| 65 virtual bool SetPosition(int64 position); |
| 66 virtual bool GetSize(int64* size_out); |
| 67 virtual bool IsStreaming(); |
| 68 |
| 69 private: |
| 70 const char* data_; |
| 71 int64 size_; |
| 72 int64 position_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(InMemoryDataReader); |
| 75 }; |
| 76 |
| 77 } // namespace media |
| 78 |
| 79 #endif // MEDIA_FILTERS_AUDIO_FILE_READER_H_ |
OLD | NEW |