Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 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> |
Glenn Kasten | c1e3ed1 | 2012-03-13 15:22:11 -0700 | [diff] [blame] | 21 | #include <media/AudioTrack.h> |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 22 | #include "M4xVSS_API.h" |
| 23 | #include "VideoEditorMain.h" |
| 24 | #include "VideoEditorTools.h" |
| 25 | #include "VideoEditorAudioPlayer.h" |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 26 | #include "NativeWindowRenderer.h" |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 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 | |
| 40 | virtual bool ready() const { return mTrack != NULL; } |
| 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; |
Marco Nelissen | 4110c10 | 2012-03-29 09:31:28 -0700 | [diff] [blame] | 48 | virtual status_t getPosition(uint32_t *position) const; |
| 49 | virtual status_t getFramesWritten(uint32_t*) const; |
| 50 | virtual int getSessionId() const; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 51 | |
| 52 | virtual status_t open( |
Jean-Michel Trivi | 8162c1a | 2012-03-02 14:34:10 -0800 | [diff] [blame] | 53 | uint32_t sampleRate, int channelCount, audio_channel_mask_t channelMask, |
Glenn Kasten | 8dcbd11 | 2012-01-04 09:30:49 -0800 | [diff] [blame] | 54 | audio_format_t format, int bufferCount, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 55 | AudioCallback cb, void *cookie, audio_output_flags_t flags, |
| 56 | const audio_offload_info_t *offloadInfo); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 57 | |
Richard Fitzgerald | d89532e | 2013-05-14 13:18:21 +0100 | [diff] [blame] | 58 | virtual status_t start(); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 59 | virtual ssize_t write(const void* buffer, size_t size); |
| 60 | virtual void stop(); |
| 61 | virtual void flush(); |
| 62 | virtual void pause(); |
| 63 | virtual void close(); |
Glenn Kasten | 813c101 | 2012-01-09 11:16:58 -0800 | [diff] [blame] | 64 | void setAudioStreamType(audio_stream_type_t streamType) { mStreamType = streamType; } |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 65 | void setVolume(float left, float right); |
| 66 | virtual status_t dump(int fd,const Vector<String16>& args) const; |
| 67 | |
| 68 | static bool isOnEmulator(); |
| 69 | static int getMinBufferCount(); |
| 70 | private: |
| 71 | static void setMinBufferCount(); |
| 72 | static void CallbackWrapper( |
| 73 | int event, void *me, void *info); |
| 74 | |
Glenn Kasten | 2799d74 | 2013-05-30 14:33:29 -0700 | [diff] [blame] | 75 | sp<AudioTrack> mTrack; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 76 | AudioCallback mCallback; |
| 77 | void * mCallbackCookie; |
Glenn Kasten | 813c101 | 2012-01-09 11:16:58 -0800 | [diff] [blame] | 78 | audio_stream_type_t mStreamType; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 79 | float mLeftVolume; |
| 80 | float mRightVolume; |
| 81 | float mMsecsPerFrame; |
| 82 | uint32_t mLatency; |
| 83 | int mSessionId; |
| 84 | static bool mIsOnEmulator; |
| 85 | static int mMinBufferCount; // 12 for emulator; otherwise 4 |
| 86 | |
| 87 | public: |
| 88 | uint32_t mNumFramesWritten; |
| 89 | void snoopWrite(const void*, size_t); |
| 90 | }; |
| 91 | |
| 92 | public: |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 93 | VideoEditorPlayer(NativeWindowRenderer* renderer); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 94 | virtual ~VideoEditorPlayer(); |
| 95 | |
| 96 | virtual status_t initCheck(); |
| 97 | |
| 98 | virtual status_t setDataSource( |
| 99 | const char *url, const KeyedVector<String8, String8> *headers); |
| 100 | |
| 101 | virtual status_t setDataSource(int fd, int64_t offset, int64_t length); |
| 102 | virtual status_t setVideoSurface(const sp<Surface> &surface); |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 103 | virtual status_t setVideoSurfaceTexture(const sp<IGraphicBufferProducer> &bufferProducer); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 104 | virtual status_t prepare(); |
| 105 | virtual status_t prepareAsync(); |
| 106 | virtual status_t start(); |
| 107 | virtual status_t stop(); |
| 108 | virtual status_t pause(); |
| 109 | virtual bool isPlaying(); |
| 110 | virtual status_t seekTo(int msec); |
| 111 | virtual status_t getCurrentPosition(int *msec); |
| 112 | virtual status_t getDuration(int *msec); |
| 113 | virtual status_t reset(); |
| 114 | virtual status_t setLooping(int loop); |
| 115 | virtual player_type playerType(); |
| 116 | virtual status_t invoke(const Parcel &request, Parcel *reply); |
| 117 | virtual void setAudioSink(const sp<AudioSink> &audioSink); |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 118 | virtual void acquireLock(); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 119 | virtual void releaseLock(); |
Gloria Wang | acb62af | 2011-04-25 17:29:16 -0700 | [diff] [blame] | 120 | virtual status_t setParameter(int key, const Parcel &request); |
| 121 | virtual status_t getParameter(int key, Parcel *reply); |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 122 | |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 123 | virtual status_t getMetadata( |
| 124 | const media::Metadata::Filter& ids, Parcel *records); |
| 125 | |
| 126 | virtual status_t loadEffectsSettings( |
| 127 | M4VSS3GPP_EffectSettings* pEffectSettings, int nEffects); |
| 128 | |
| 129 | virtual status_t loadAudioMixSettings( |
| 130 | M4xVSS_AudioMixingSettings* pAudioMixSettings); |
| 131 | |
| 132 | virtual status_t setAudioMixPCMFileHandle( |
| 133 | M4OSA_Context pAudioMixPCMFileHandle); |
| 134 | |
| 135 | virtual status_t setAudioMixStoryBoardParam( |
| 136 | M4OSA_UInt32 x, M4OSA_UInt32 y, M4OSA_UInt32 z); |
| 137 | |
| 138 | virtual status_t setPlaybackBeginTime(uint32_t msec); |
| 139 | virtual status_t setPlaybackEndTime(uint32_t msec); |
| 140 | virtual status_t setStoryboardStartTime(uint32_t msec); |
| 141 | virtual status_t setProgressCallbackInterval(uint32_t cbInterval); |
| 142 | |
| 143 | virtual status_t setMediaRenderingMode(M4xVSS_MediaRendering mode, |
| 144 | M4VIDEOEDITING_VideoFrameSize outputVideoSize); |
| 145 | |
| 146 | virtual status_t resetJniCallbackTimeStamp(); |
| 147 | virtual status_t setImageClipProperties(uint32_t width, uint32_t height); |
| 148 | virtual status_t readFirstVideoFrame(); |
| 149 | virtual status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs); |
| 150 | |
| 151 | status_t setAudioPlayer(VideoEditorAudioPlayer *audioPlayer); |
| 152 | private: |
| 153 | PreviewPlayer *mPlayer; |
| 154 | sp<VeAudioOutput> mVeAudioSink; |
| 155 | |
| 156 | VideoEditorPlayer(const VideoEditorPlayer &); |
| 157 | VideoEditorPlayer &operator=(const VideoEditorPlayer &); |
| 158 | }; |
| 159 | |
| 160 | } // namespace android |
| 161 | |
| 162 | #endif // ANDROID_VIDEOEDITOR_PLAYER_H |