Home | History | Annotate | Download | only in lvpp
      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 
     17 #ifndef VE_AUDIO_PLAYER_H_
     18 #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>
     24 
     25 #include "M4xVSS_API.h"
     26 #include "VideoEditorMain.h"
     27 #include "M4OSA_FileReader.h"
     28 #include "VideoEditorBGAudioProcessing.h"
     29 
     30 
     31 namespace android {
     32 
     33 class MediaSource;
     34 class AudioTrack;
     35 class PreviewPlayer;
     36 
     37 class VideoEditorAudioPlayer : public TimeSource {
     38 public:
     39     enum {
     40         REACHED_EOS,
     41         SEEK_COMPLETE
     42     };
     43 
     44     VideoEditorAudioPlayer(const sp<MediaPlayerBase::AudioSink> &audioSink,
     45         PreviewPlayer *audioObserver = NULL);
     46 
     47     ~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);
     58 
     59     status_t start(bool sourceAlreadyStarted = false);
     60     void pause(bool playPendingSamples = false);
     61     void resume();
     62     status_t seekTo(int64_t time_us);
     63     bool isSeeking();
     64     bool reachedEOS(status_t *finalStatus);
     65 
     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 
     73     void setObserver(PreviewPlayer *observer);
     74     void setSource(const sp<MediaSource> &source);
     75     sp<MediaSource> getSource();
     76 
     77     bool isStarted();
     78 private:
     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 
     93     sp<MediaSource> mSource;
     94     AudioTrack *mAudioTrack;
     95 
     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);
    124     size_t fillBuffer(void *data, size_t size);
    125     static size_t AudioSinkCallback(
    126             MediaPlayerBase::AudioSink *audioSink,
    127             void *data, size_t size, void *me);
    128 
    129     void reset();
    130     void clear();
    131     int64_t getRealTimeUs_l();
    132     void setPrimaryTrackVolume(
    133             M4OSA_Int16 *data, M4OSA_UInt32 size, M4OSA_Float volLevel);
    134 
    135     VideoEditorAudioPlayer(const VideoEditorAudioPlayer &);
    136     VideoEditorAudioPlayer &operator=(const VideoEditorAudioPlayer &);
    137 };
    138 
    139 }  // namespace android
    140 
    141 #endif  // VE_AUDIO_PLAYER_H_
    142