• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ANDROID_VIDEOEDITOR_PLAYER_H
18 #define ANDROID_VIDEOEDITOR_PLAYER_H
19 
20 #include <media/MediaPlayerInterface.h>
21 #include "AudioTrack.h"
22 #include "M4xVSS_API.h"
23 #include "VideoEditorMain.h"
24 #include "VideoEditorTools.h"
25 #include "VideoEditorAudioPlayer.h"
26 #include "NativeWindowRenderer.h"
27 
28 namespace android {
29 
30 struct PreviewPlayer;
31 
32 class VideoEditorPlayer : public MediaPlayerInterface {
33     public:
34     class VeAudioOutput: public MediaPlayerBase::AudioSink
35     {
36     public:
37                                 VeAudioOutput();
38         virtual                 ~VeAudioOutput();
39 
ready()40         virtual bool            ready() const { return mTrack != NULL; }
realtime()41         virtual bool            realtime() const { return true; }
42         virtual ssize_t         bufferSize() const;
43         virtual ssize_t         frameCount() const;
44         virtual ssize_t         channelCount() const;
45         virtual ssize_t         frameSize() const;
46         virtual uint32_t        latency() const;
47         virtual float           msecsPerFrame() const;
48         virtual status_t        getPosition(uint32_t *position);
49         virtual int             getSessionId();
50 
51         virtual status_t        open(
52                 uint32_t sampleRate, int channelCount,
53                 int format, int bufferCount,
54                 AudioCallback cb, void *cookie);
55 
56         virtual void            start();
57         virtual ssize_t         write(const void* buffer, size_t size);
58         virtual void            stop();
59         virtual void            flush();
60         virtual void            pause();
61         virtual void            close();
setAudioStreamType(int streamType)62         void setAudioStreamType(int streamType) { mStreamType = streamType; }
63                 void            setVolume(float left, float right);
64         virtual status_t        dump(int fd,const Vector<String16>& args) const;
65 
66         static bool             isOnEmulator();
67         static int              getMinBufferCount();
68     private:
69         static void             setMinBufferCount();
70         static void             CallbackWrapper(
71                 int event, void *me, void *info);
72 
73         AudioTrack*             mTrack;
74         AudioCallback           mCallback;
75         void *                  mCallbackCookie;
76         int                     mStreamType;
77         float                   mLeftVolume;
78         float                   mRightVolume;
79         float                   mMsecsPerFrame;
80         uint32_t                mLatency;
81         int                     mSessionId;
82         static bool             mIsOnEmulator;
83         static int              mMinBufferCount; // 12 for emulator; otherwise 4
84 
85         public:
86         uint32_t                mNumFramesWritten;
87         void                    snoopWrite(const void*, size_t);
88     };
89 
90 public:
91     VideoEditorPlayer(NativeWindowRenderer* renderer);
92     virtual ~VideoEditorPlayer();
93 
94     virtual status_t initCheck();
95 
96     virtual status_t setDataSource(
97             const char *url, const KeyedVector<String8, String8> *headers);
98 
99     virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
100     virtual status_t setVideoSurface(const sp<Surface> &surface);
101     virtual status_t setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
102     virtual status_t prepare();
103     virtual status_t prepareAsync();
104     virtual status_t start();
105     virtual status_t stop();
106     virtual status_t pause();
107     virtual bool isPlaying();
108     virtual status_t seekTo(int msec);
109     virtual status_t getCurrentPosition(int *msec);
110     virtual status_t getDuration(int *msec);
111     virtual status_t reset();
112     virtual status_t setLooping(int loop);
113     virtual player_type playerType();
114     virtual status_t invoke(const Parcel &request, Parcel *reply);
115     virtual void setAudioSink(const sp<AudioSink> &audioSink);
116     virtual void acquireLock();
117     virtual void releaseLock();
118     virtual status_t setParameter(int key, const Parcel &request);
119     virtual status_t getParameter(int key, Parcel *reply);
120 
121     virtual status_t getMetadata(
122                         const media::Metadata::Filter& ids, Parcel *records);
123 
124     virtual status_t loadEffectsSettings(
125                          M4VSS3GPP_EffectSettings* pEffectSettings, int nEffects);
126 
127     virtual status_t loadAudioMixSettings(
128                          M4xVSS_AudioMixingSettings* pAudioMixSettings);
129 
130     virtual status_t setAudioMixPCMFileHandle(
131                          M4OSA_Context pAudioMixPCMFileHandle);
132 
133     virtual status_t setAudioMixStoryBoardParam(
134                          M4OSA_UInt32 x, M4OSA_UInt32 y, M4OSA_UInt32 z);
135 
136     virtual status_t setPlaybackBeginTime(uint32_t msec);
137     virtual status_t setPlaybackEndTime(uint32_t msec);
138     virtual status_t setStoryboardStartTime(uint32_t msec);
139     virtual status_t setProgressCallbackInterval(uint32_t cbInterval);
140 
141     virtual status_t setMediaRenderingMode(M4xVSS_MediaRendering mode,
142                           M4VIDEOEDITING_VideoFrameSize outputVideoSize);
143 
144     virtual status_t resetJniCallbackTimeStamp();
145     virtual status_t setImageClipProperties(uint32_t width, uint32_t height);
146     virtual status_t readFirstVideoFrame();
147     virtual status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs);
148 
149     status_t setAudioPlayer(VideoEditorAudioPlayer *audioPlayer);
150 private:
151     PreviewPlayer       *mPlayer;
152     sp<VeAudioOutput>    mVeAudioSink;
153 
154     VideoEditorPlayer(const VideoEditorPlayer &);
155     VideoEditorPlayer &operator=(const VideoEditorPlayer &);
156 };
157 
158 }  // namespace android
159 
160 #endif  // ANDROID_VIDEOEDITOR_PLAYER_H
161