blob: 85829e7c5dfeac97d5564da7ffd5ab216b99f5c4 [file] [log] [blame]
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001/*
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002 * 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
Kenny Rooteb5b2652011-02-08 11:13:19 -080017#include <stdint.h>
18
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080019#include <utils/RefBase.h>
James Donge6815bf2011-05-02 18:23:42 -070020#include <utils/threads.h>
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080021
22#include <media/stagefright/MediaSource.h>
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080023
24#include "AudioBufferProvider.h"
25#include "AudioResampler.h"
26
27namespace android {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080028
James Donge6815bf2011-05-02 18:23:42 -070029struct MediaBuffer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080030
31class VideoEditorSRC : public MediaSource , public AudioBufferProvider {
32
33 public:
34 VideoEditorSRC(
35 const sp<MediaSource> &source);
36
37 virtual status_t start (MetaData *params = NULL);
38 virtual status_t stop();
39 virtual sp<MetaData> getFormat();
40 virtual status_t read (
41 MediaBuffer **buffer, const ReadOptions *options = NULL);
42
43 virtual status_t getNextBuffer(Buffer* buffer);
44 virtual void releaseBuffer(Buffer* buffer);
45
46 void setResampling(int32_t sampleRate=kFreq32000Hz);
47
48 enum { //Sampling freq
49 kFreq8000Hz = 8000,
James Donge6815bf2011-05-02 18:23:42 -070050 kFreq11025Hz = 11025,
51 kFreq12000Hz = 12000,
52 kFreq16000Hz = 16000,
53 kFreq22050Hz = 22050,
54 kFreq240000Hz = 24000,
55 kFreq32000Hz = 32000,
56 kFreq44100 = 44100,
57 kFreq48000 = 48000,
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080058 };
59
60 static const uint16_t UNITY_GAIN = 0x1000;
61 static const int32_t DEFAULT_SAMPLING_FREQ = (int32_t)kFreq32000Hz; // kFreq44100;
62
63 protected :
64 virtual ~VideoEditorSRC();
65 private:
66
67 VideoEditorSRC();
68 VideoEditorSRC &operator=(const VideoEditorSRC &);
69
70 AudioResampler *mResampler;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080071 sp<MediaSource> mSource;
72 MediaBuffer *mCopyBuffer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080073 int mBitDepth;
74 int mChannelCnt;
75 int mSampleRate;
76 int32_t mOutputSampleRate;
77 bool mStarted;
78 bool mIsResamplingRequired;
79 bool mIsChannelConvertionRequired; // for mono to stereo
80 sp<MetaData> mOutputFormat;
81 Mutex mLock;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080082
James Donge6815bf2011-05-02 18:23:42 -070083 uint8_t* mInterframeBuffer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080084 int32_t mInterframeBufferPosition;
85 int32_t mLeftover;
86 int32_t mLastReadSize ;
87
88 int64_t mInitialTimeStampUs;
89 int64_t mAccuOutBufferSize;
90
91 int64_t mSeekTimeUs;
92 ReadOptions::SeekMode mSeekMode;
Santosh Madhava9785cdf2011-02-08 23:26:18 -080093 int16_t *mReSampledBuffer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080094
95};
96
97} //namespce android
98