• 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 <media/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) const;
49         virtual status_t        getFramesWritten(uint32_t*) const;
50         virtual int             getSessionId() const;
51         virtual uint32_t        getSampleRate() const;
52 
53         virtual status_t        open(
54                 uint32_t sampleRate, int channelCount, audio_channel_mask_t channelMask,
55                 audio_format_t format, int bufferCount,
56                 AudioCallback cb, void *cookie, audio_output_flags_t flags,
57                 const audio_offload_info_t *offloadInfo);
58 
59         virtual status_t        start();
60         virtual ssize_t         write(const void* buffer, size_t size);
61         virtual void            stop();
62         virtual void            flush();
63         virtual void            pause();
64         virtual void            close();
setAudioStreamType(audio_stream_type_t streamType)65         void setAudioStreamType(audio_stream_type_t streamType) { mStreamType = streamType; }
getAudioStreamType()66         virtual audio_stream_type_t getAudioStreamType() const { return mStreamType; }
67                 void            setVolume(float left, float right);
68         virtual status_t        dump(int fd,const Vector<String16>& args) const;
69 
70         static bool             isOnEmulator();
71         static int              getMinBufferCount();
72     private:
73         static void             setMinBufferCount();
74         static void             CallbackWrapper(
75                 int event, void *me, void *info);
76 
77         sp<AudioTrack>          mTrack;
78         AudioCallback           mCallback;
79         void *                  mCallbackCookie;
80         audio_stream_type_t     mStreamType;
81         float                   mLeftVolume;
82         float                   mRightVolume;
83         float                   mMsecsPerFrame;
84         uint32_t                mLatency;
85         int                     mSessionId;
86         static bool             mIsOnEmulator;
87         static int              mMinBufferCount; // 12 for emulator; otherwise 4
88 
89         public:
90         uint32_t                mNumFramesWritten;
91         void                    snoopWrite(const void*, size_t);
92     };
93 
94 public:
95     VideoEditorPlayer(NativeWindowRenderer* renderer);
96     virtual ~VideoEditorPlayer();
97 
98     virtual status_t initCheck();
99 
100     virtual status_t setDataSource(
101             const char *url, const KeyedVector<String8, String8> *headers);
102 
103     virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
104     virtual status_t setVideoSurface(const sp<Surface> &surface);
105     virtual status_t setVideoSurfaceTexture(const sp<IGraphicBufferProducer> &bufferProducer);
106     virtual status_t prepare();
107     virtual status_t prepareAsync();
108     virtual status_t start();
109     virtual status_t stop();
110     virtual status_t pause();
111     virtual bool isPlaying();
112     virtual status_t seekTo(int msec);
113     virtual status_t getCurrentPosition(int *msec);
114     virtual status_t getDuration(int *msec);
115     virtual status_t reset();
116     virtual status_t setLooping(int loop);
117     virtual player_type playerType();
118     virtual status_t invoke(const Parcel &request, Parcel *reply);
119     virtual void setAudioSink(const sp<AudioSink> &audioSink);
120     virtual void acquireLock();
121     virtual void releaseLock();
122     virtual status_t setParameter(int key, const Parcel &request);
123     virtual status_t getParameter(int key, Parcel *reply);
124 
125     virtual status_t getMetadata(
126                         const media::Metadata::Filter& ids, Parcel *records);
127 
128     virtual status_t loadEffectsSettings(
129                          M4VSS3GPP_EffectSettings* pEffectSettings, int nEffects);
130 
131     virtual status_t loadAudioMixSettings(
132                          M4xVSS_AudioMixingSettings* pAudioMixSettings);
133 
134     virtual status_t setAudioMixPCMFileHandle(
135                          M4OSA_Context pAudioMixPCMFileHandle);
136 
137     virtual status_t setAudioMixStoryBoardParam(
138                          M4OSA_UInt32 x, M4OSA_UInt32 y, M4OSA_UInt32 z);
139 
140     virtual status_t setPlaybackBeginTime(uint32_t msec);
141     virtual status_t setPlaybackEndTime(uint32_t msec);
142     virtual status_t setStoryboardStartTime(uint32_t msec);
143     virtual status_t setProgressCallbackInterval(uint32_t cbInterval);
144 
145     virtual status_t setMediaRenderingMode(M4xVSS_MediaRendering mode,
146                           M4VIDEOEDITING_VideoFrameSize outputVideoSize);
147 
148     virtual status_t resetJniCallbackTimeStamp();
149     virtual status_t setImageClipProperties(uint32_t width, uint32_t height);
150     virtual status_t readFirstVideoFrame();
151     virtual status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs);
152 
153     status_t setAudioPlayer(VideoEditorAudioPlayer *audioPlayer);
154 private:
155     PreviewPlayer       *mPlayer;
156     sp<VeAudioOutput>    mVeAudioSink;
157 
158     VideoEditorPlayer(const VideoEditorPlayer &);
159     VideoEditorPlayer &operator=(const VideoEditorPlayer &);
160 };
161 
162 }  // namespace android
163 
164 #endif  // ANDROID_VIDEOEDITOR_PLAYER_H
165