blob: 781e4bc198e4171dacf0a5d159124721b61b7c19 [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 ANDROID_VIDEOEDITOR_PLAYER_H
18#define ANDROID_VIDEOEDITOR_PLAYER_H
19
20#include <media/MediaPlayerInterface.h>
Glenn Kastenc1e3ed12012-03-13 15:22:11 -070021#include <media/AudioTrack.h>
Chih-Chung Chang99698662011-06-30 14:21:38 +080022#include "M4xVSS_API.h"
23#include "VideoEditorMain.h"
24#include "VideoEditorTools.h"
25#include "VideoEditorAudioPlayer.h"
Chih-Chung Chang43fcc392011-08-02 16:17:39 +080026#include "NativeWindowRenderer.h"
Chih-Chung Chang99698662011-06-30 14:21:38 +080027
28namespace android {
29
30struct PreviewPlayer;
31
32class 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 Nelissen4110c102012-03-29 09:31:28 -070048 virtual status_t getPosition(uint32_t *position) const;
49 virtual status_t getFramesWritten(uint32_t*) const;
50 virtual int getSessionId() const;
Eric Laurent6f59db12013-07-26 17:16:50 -070051 virtual uint32_t getSampleRate() const;
Chih-Chung Chang99698662011-06-30 14:21:38 +080052
53 virtual status_t open(
Jean-Michel Trivi8162c1a2012-03-02 14:34:10 -080054 uint32_t sampleRate, int channelCount, audio_channel_mask_t channelMask,
Glenn Kasten8dcbd112012-01-04 09:30:49 -080055 audio_format_t format, int bufferCount,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000056 AudioCallback cb, void *cookie, audio_output_flags_t flags,
57 const audio_offload_info_t *offloadInfo);
Chih-Chung Chang99698662011-06-30 14:21:38 +080058
Richard Fitzgeraldd89532e2013-05-14 13:18:21 +010059 virtual status_t start();
Chih-Chung Chang99698662011-06-30 14:21:38 +080060 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();
Glenn Kasten813c1012012-01-09 11:16:58 -080065 void setAudioStreamType(audio_stream_type_t streamType) { mStreamType = streamType; }
Eric Laurent22612342013-11-14 17:28:47 -080066 virtual audio_stream_type_t getAudioStreamType() const { return mStreamType; }
Chih-Chung Chang99698662011-06-30 14:21:38 +080067 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
Glenn Kasten2799d742013-05-30 14:33:29 -070077 sp<AudioTrack> mTrack;
Chih-Chung Chang99698662011-06-30 14:21:38 +080078 AudioCallback mCallback;
79 void * mCallbackCookie;
Glenn Kasten813c1012012-01-09 11:16:58 -080080 audio_stream_type_t mStreamType;
Chih-Chung Chang99698662011-06-30 14:21:38 +080081 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
94public:
Chih-Chung Chang43fcc392011-08-02 16:17:39 +080095 VideoEditorPlayer(NativeWindowRenderer* renderer);
Chih-Chung Chang99698662011-06-30 14:21:38 +080096 virtual ~VideoEditorPlayer();
97
98 virtual status_t initCheck();
99
100 virtual status_t setDataSource(
Andreas Huber1b86fe02014-01-29 11:13:26 -0800101 const sp<IMediaHTTPService> &httpService,
Chih-Chung Chang99698662011-06-30 14:21:38 +0800102 const char *url, const KeyedVector<String8, String8> *headers);
103
104 virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
105 virtual status_t setVideoSurface(const sp<Surface> &surface);
Andy McFadden8ba01022012-12-18 09:46:54 -0800106 virtual status_t setVideoSurfaceTexture(const sp<IGraphicBufferProducer> &bufferProducer);
Chih-Chung Chang99698662011-06-30 14:21:38 +0800107 virtual status_t prepare();
108 virtual status_t prepareAsync();
109 virtual status_t start();
110 virtual status_t stop();
111 virtual status_t pause();
112 virtual bool isPlaying();
113 virtual status_t seekTo(int msec);
114 virtual status_t getCurrentPosition(int *msec);
115 virtual status_t getDuration(int *msec);
116 virtual status_t reset();
117 virtual status_t setLooping(int loop);
118 virtual player_type playerType();
119 virtual status_t invoke(const Parcel &request, Parcel *reply);
120 virtual void setAudioSink(const sp<AudioSink> &audioSink);
Raghavender Pallafa31daf2011-03-18 22:32:51 -0700121 virtual void acquireLock();
Chih-Chung Chang99698662011-06-30 14:21:38 +0800122 virtual void releaseLock();
Gloria Wangacb62af2011-04-25 17:29:16 -0700123 virtual status_t setParameter(int key, const Parcel &request);
124 virtual status_t getParameter(int key, Parcel *reply);
Raghavender Pallafa31daf2011-03-18 22:32:51 -0700125
Chih-Chung Chang99698662011-06-30 14:21:38 +0800126 virtual status_t getMetadata(
127 const media::Metadata::Filter& ids, Parcel *records);
128
129 virtual status_t loadEffectsSettings(
130 M4VSS3GPP_EffectSettings* pEffectSettings, int nEffects);
131
132 virtual status_t loadAudioMixSettings(
133 M4xVSS_AudioMixingSettings* pAudioMixSettings);
134
135 virtual status_t setAudioMixPCMFileHandle(
136 M4OSA_Context pAudioMixPCMFileHandle);
137
138 virtual status_t setAudioMixStoryBoardParam(
139 M4OSA_UInt32 x, M4OSA_UInt32 y, M4OSA_UInt32 z);
140
141 virtual status_t setPlaybackBeginTime(uint32_t msec);
142 virtual status_t setPlaybackEndTime(uint32_t msec);
143 virtual status_t setStoryboardStartTime(uint32_t msec);
144 virtual status_t setProgressCallbackInterval(uint32_t cbInterval);
145
146 virtual status_t setMediaRenderingMode(M4xVSS_MediaRendering mode,
147 M4VIDEOEDITING_VideoFrameSize outputVideoSize);
148
149 virtual status_t resetJniCallbackTimeStamp();
150 virtual status_t setImageClipProperties(uint32_t width, uint32_t height);
151 virtual status_t readFirstVideoFrame();
152 virtual status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs);
153
154 status_t setAudioPlayer(VideoEditorAudioPlayer *audioPlayer);
155private:
156 PreviewPlayer *mPlayer;
157 sp<VeAudioOutput> mVeAudioSink;
158
159 VideoEditorPlayer(const VideoEditorPlayer &);
160 VideoEditorPlayer &operator=(const VideoEditorPlayer &);
161};
162
163} // namespace android
164
165#endif // ANDROID_VIDEOEDITOR_PLAYER_H