blob: 2caf5e8d0c689e9d4317a2954beb215e6065246d [file] [log] [blame]
Chih-Chung Chang99698662011-06-30 14:21:38 +08001/*
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
17#ifndef VE_AUDIO_PLAYER_H_
Chih-Chung Chang99698662011-06-30 14:21:38 +080018#define VE_AUDIO_PLAYER_H_
19
20#include <media/MediaPlayerInterface.h>
21#include <media/stagefright/MediaBuffer.h>
22#include <media/stagefright/TimeSource.h>
23#include <utils/threads.h>
James Dong727f9e12012-01-20 13:09:13 -080024
Chih-Chung Chang99698662011-06-30 14:21:38 +080025#include "M4xVSS_API.h"
26#include "VideoEditorMain.h"
27#include "M4OSA_FileReader.h"
28#include "VideoEditorBGAudioProcessing.h"
James Dong727f9e12012-01-20 13:09:13 -080029
Chih-Chung Chang99698662011-06-30 14:21:38 +080030
31namespace android {
32
33class MediaSource;
34class AudioTrack;
35class PreviewPlayer;
36
James Dong727f9e12012-01-20 13:09:13 -080037class VideoEditorAudioPlayer : public TimeSource {
Chih-Chung Chang99698662011-06-30 14:21:38 +080038public:
39 enum {
40 REACHED_EOS,
41 SEEK_COMPLETE
42 };
43
44 VideoEditorAudioPlayer(const sp<MediaPlayerBase::AudioSink> &audioSink,
James Dong00f742c2012-01-13 17:34:42 -080045 PreviewPlayer *audioObserver = NULL);
Chih-Chung Chang99698662011-06-30 14:21:38 +080046
James Dong727f9e12012-01-20 13:09:13 -080047 ~VideoEditorAudioPlayer();
48
49 // Return time in us.
50 int64_t getRealTimeUs();
51
52 // Returns the timestamp of the last buffer played (in us).
53 int64_t getMediaTimeUs();
54
55 // Returns true iff a mapping is established, i.e. the AudioPlayerBase
56 // has played at least one frame of audio.
57 bool getMediaTimeMapping(int64_t *realtime_us, int64_t *mediatime_us);
Chih-Chung Chang99698662011-06-30 14:21:38 +080058
59 status_t start(bool sourceAlreadyStarted = false);
James Dong727f9e12012-01-20 13:09:13 -080060 void pause(bool playPendingSamples = false);
Richard Fitzgerald94ea60f2013-05-14 15:52:03 +010061 status_t resume();
James Dong727f9e12012-01-20 13:09:13 -080062 status_t seekTo(int64_t time_us);
63 bool isSeeking();
64 bool reachedEOS(status_t *finalStatus);
Chih-Chung Chang99698662011-06-30 14:21:38 +080065
66 void setAudioMixSettings(M4xVSS_AudioMixingSettings* pAudioMixSettings);
67 void setAudioMixPCMFileHandle(M4OSA_Context pBGAudioPCMFileHandle);
68 void setAudioMixStoryBoardSkimTimeStamp(
69 M4OSA_UInt32 pBGAudioStoryBoardSkimTimeStamp,
70 M4OSA_UInt32 pBGAudioCurrentMediaBeginCutTS,
71 M4OSA_UInt32 pBGAudioCurrentMediaVolumeVal);
72
James Dong00f742c2012-01-13 17:34:42 -080073 void setObserver(PreviewPlayer *observer);
Chih-Chung Chang99698662011-06-30 14:21:38 +080074 void setSource(const sp<MediaSource> &source);
75 sp<MediaSource> getSource();
76
77 bool isStarted();
78private:
79
80 M4xVSS_AudioMixingSettings *mAudioMixSettings;
81 VideoEditorBGAudioProcessing *mAudioProcess;
82
83 M4OSA_Context mBGAudioPCMFileHandle;
84 int64_t mBGAudioPCMFileLength;
85 int64_t mBGAudioPCMFileTrimmedLength;
86 int64_t mBGAudioPCMFileDuration;
87 int64_t mBGAudioPCMFileSeekPoint;
88 int64_t mBGAudioPCMFileOriginalSeekPoint;
89 int64_t mBGAudioStoryBoardSkimTimeStamp;
90 int64_t mBGAudioStoryBoardCurrentMediaBeginCutTS;
91 int64_t mBGAudioStoryBoardCurrentMediaVolumeVal;
92
James Dong727f9e12012-01-20 13:09:13 -080093 sp<MediaSource> mSource;
Glenn Kasten2799d742013-05-30 14:33:29 -070094 sp<AudioTrack> mAudioTrack;
James Dong727f9e12012-01-20 13:09:13 -080095
96 MediaBuffer *mInputBuffer;
97
98 int mSampleRate;
99 int64_t mLatencyUs;
100 size_t mFrameSize;
101
102 Mutex mLock;
103 int64_t mNumFramesPlayed;
104
105 int64_t mPositionTimeMediaUs;
106 int64_t mPositionTimeRealUs;
107
108 bool mSeeking;
109 bool mReachedEOS;
110 status_t mFinalStatus;
111 int64_t mSeekTimeUs;
112
113 bool mStarted;
114
115 bool mIsFirstBuffer;
116 status_t mFirstBufferResult;
117 MediaBuffer *mFirstBuffer;
118
119 sp<MediaPlayerBase::AudioSink> mAudioSink;
120 PreviewPlayer *mObserver;
121
122 static void AudioCallback(int event, void *user, void *info);
123 void AudioCallback(int event, void *info);
Chih-Chung Chang99698662011-06-30 14:21:38 +0800124 size_t fillBuffer(void *data, size_t size);
Chih-Chung Chang99698662011-06-30 14:21:38 +0800125 static size_t AudioSinkCallback(
126 MediaPlayerBase::AudioSink *audioSink,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000127 void *data, size_t size, void *me,
128 MediaPlayerBase::AudioSink::cb_event_t event);
Chih-Chung Chang99698662011-06-30 14:21:38 +0800129
James Dong727f9e12012-01-20 13:09:13 -0800130 void reset();
131 void clear();
132 int64_t getRealTimeUs_l();
133 void setPrimaryTrackVolume(
134 M4OSA_Int16 *data, M4OSA_UInt32 size, M4OSA_Float volLevel);
135
Chih-Chung Chang99698662011-06-30 14:21:38 +0800136 VideoEditorAudioPlayer(const VideoEditorAudioPlayer &);
137 VideoEditorAudioPlayer &operator=(const VideoEditorAudioPlayer &);
138};
139
140} // namespace android
141
142#endif // VE_AUDIO_PLAYER_H_