Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 17 | |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 18 | #include <stdint.h> |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 19 | #include <media/stagefright/MediaSource.h> |
Glenn Kasten | 2dd4bdd | 2012-08-29 11:10:32 -0700 | [diff] [blame^] | 20 | #include <media/AudioBufferProvider.h> |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 21 | #include "AudioResampler.h" |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | struct MediaBuffer; |
| 26 | |
| 27 | class VideoEditorSRC : public MediaSource , public AudioBufferProvider { |
| 28 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 29 | public: |
| 30 | VideoEditorSRC(const sp<MediaSource> &source); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 31 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 32 | virtual status_t start (MetaData *params = NULL); |
| 33 | virtual status_t stop(); |
| 34 | virtual sp<MetaData> getFormat(); |
| 35 | virtual status_t read ( |
| 36 | MediaBuffer **buffer, const ReadOptions *options = NULL); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 37 | |
John Grossman | 7719f63 | 2012-02-10 13:46:24 -0800 | [diff] [blame] | 38 | virtual status_t getNextBuffer(Buffer* buffer, int64_t pts); |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 39 | virtual void releaseBuffer(Buffer* buffer); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 40 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 41 | // Sampling freqencies |
| 42 | enum { |
| 43 | kFreq8000Hz = 8000, |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 44 | kFreq11025Hz = 11025, |
| 45 | kFreq12000Hz = 12000, |
| 46 | kFreq16000Hz = 16000, |
| 47 | kFreq22050Hz = 22050, |
James Dong | 7a4097c | 2012-01-17 14:23:29 -0800 | [diff] [blame] | 48 | kFreq24000Hz = 24000, |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 49 | kFreq32000Hz = 32000, |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 50 | kFreq44100Hz = 44100, |
| 51 | kFreq48000Hz = 48000, |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 52 | }; |
| 53 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 54 | protected : |
| 55 | virtual ~VideoEditorSRC(); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 56 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 57 | private: |
| 58 | AudioResampler *mResampler; |
| 59 | sp<MediaSource> mSource; |
| 60 | int mChannelCnt; |
| 61 | int mSampleRate; |
| 62 | int32_t mOutputSampleRate; |
| 63 | bool mStarted; |
| 64 | sp<MetaData> mOutputFormat; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 65 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 66 | MediaBuffer* mBuffer; |
| 67 | int32_t mLeftover; |
| 68 | bool mFormatChanged; |
| 69 | bool mStopPending; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 70 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 71 | int64_t mInitialTimeStampUs; |
| 72 | int64_t mAccuOutBufferSize; |
Rajneesh Chowdury | 1c3c543 | 2011-07-20 13:47:34 -0700 | [diff] [blame] | 73 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 74 | int64_t mSeekTimeUs; |
| 75 | ReadOptions::SeekMode mSeekMode; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 76 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 77 | VideoEditorSRC(); |
| 78 | void checkAndSetResampler(); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 79 | |
James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 80 | // Don't call me |
| 81 | VideoEditorSRC(const VideoEditorSRC&); |
| 82 | VideoEditorSRC &operator=(const VideoEditorSRC &); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 83 | |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } //namespce android |
| 87 | |