blob: 8bfd9914bc45d7be56926ff3633f370577d0c692 [file] [log] [blame]
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001/*
2 * Copyright (C) 2011 NXP Software
3 * Copyright (C) 2011 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Kenny Rooteb5b2652011-02-08 11:13:19 -080018#include <stdint.h>
19
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080020#include <utils/RefBase.h>
James Donge6815bf2011-05-02 18:23:42 -070021#include <utils/threads.h>
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080022
23#include <media/stagefright/MediaSource.h>
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080024
25#include "AudioBufferProvider.h"
26#include "AudioResampler.h"
27
28namespace android {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080029
James Donge6815bf2011-05-02 18:23:42 -070030struct MediaBuffer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080031
32class VideoEditorSRC : public MediaSource , public AudioBufferProvider {
33
34 public:
35 VideoEditorSRC(
36 const sp<MediaSource> &source);
37
38 virtual status_t start (MetaData *params = NULL);
39 virtual status_t stop();
40 virtual sp<MetaData> getFormat();
41 virtual status_t read (
42 MediaBuffer **buffer, const ReadOptions *options = NULL);
43
44 virtual status_t getNextBuffer(Buffer* buffer);
45 virtual void releaseBuffer(Buffer* buffer);
46
47 void setResampling(int32_t sampleRate=kFreq32000Hz);
48
49 enum { //Sampling freq
50 kFreq8000Hz = 8000,
James Donge6815bf2011-05-02 18:23:42 -070051 kFreq11025Hz = 11025,
52 kFreq12000Hz = 12000,
53 kFreq16000Hz = 16000,
54 kFreq22050Hz = 22050,
55 kFreq240000Hz = 24000,
56 kFreq32000Hz = 32000,
57 kFreq44100 = 44100,
58 kFreq48000 = 48000,
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080059 };
60
61 static const uint16_t UNITY_GAIN = 0x1000;
62 static const int32_t DEFAULT_SAMPLING_FREQ = (int32_t)kFreq32000Hz; // kFreq44100;
63
64 protected :
65 virtual ~VideoEditorSRC();
66 private:
67
68 VideoEditorSRC();
69 VideoEditorSRC &operator=(const VideoEditorSRC &);
70
71 AudioResampler *mResampler;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080072 sp<MediaSource> mSource;
73 MediaBuffer *mCopyBuffer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080074 int mBitDepth;
75 int mChannelCnt;
76 int mSampleRate;
77 int32_t mOutputSampleRate;
78 bool mStarted;
79 bool mIsResamplingRequired;
80 bool mIsChannelConvertionRequired; // for mono to stereo
81 sp<MetaData> mOutputFormat;
82 Mutex mLock;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080083
James Donge6815bf2011-05-02 18:23:42 -070084 uint8_t* mInterframeBuffer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080085 int32_t mInterframeBufferPosition;
86 int32_t mLeftover;
87 int32_t mLastReadSize ;
88
89 int64_t mInitialTimeStampUs;
90 int64_t mAccuOutBufferSize;
91
92 int64_t mSeekTimeUs;
93 ReadOptions::SeekMode mSeekMode;
Santosh Madhava9785cdf2011-02-08 23:26:18 -080094 int16_t *mReSampledBuffer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080095
96};
97
98} //namespce android
99