19969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang/*
29969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang * Copyright (C) 2011 The Android Open Source Project
39969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang *
49969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang * Licensed under the Apache License, Version 2.0 (the "License");
59969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang * you may not use this file except in compliance with the License.
69969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang * You may obtain a copy of the License at
79969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang *
89969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang *      http://www.apache.org/licenses/LICENSE-2.0
99969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang *
109969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang * Unless required by applicable law or agreed to in writing, software
119969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang * distributed under the License is distributed on an "AS IS" BASIS,
129969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang * See the License for the specific language governing permissions and
149969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang * limitations under the License.
159969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang */
169969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
179969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang#ifndef ANDROID_VIDEOEDITOR_PLAYER_H
189969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang#define ANDROID_VIDEOEDITOR_PLAYER_H
199969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
209969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang#include <media/MediaPlayerInterface.h>
21c1e3ed15d86337361c11fc4bb425ae252eceb946Glenn Kasten#include <media/AudioTrack.h>
229969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang#include "M4xVSS_API.h"
239969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang#include "VideoEditorMain.h"
249969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang#include "VideoEditorTools.h"
259969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang#include "VideoEditorAudioPlayer.h"
2643fcc396614a587851e2b7c4cea2876ec58b8648Chih-Chung Chang#include "NativeWindowRenderer.h"
279969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
289969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Changnamespace android {
299969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
309969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Changstruct PreviewPlayer;
319969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
329969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Changclass VideoEditorPlayer : public MediaPlayerInterface {
339969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    public:
349969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    class VeAudioOutput: public MediaPlayerBase::AudioSink
359969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    {
369969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    public:
379969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang                                VeAudioOutput();
389969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual                 ~VeAudioOutput();
399969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
409969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual bool            ready() const { return mTrack != NULL; }
419969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual bool            realtime() const { return true; }
429969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual ssize_t         bufferSize() const;
439969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual ssize_t         frameCount() const;
449969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual ssize_t         channelCount() const;
459969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual ssize_t         frameSize() const;
469969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual uint32_t        latency() const;
479969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual float           msecsPerFrame() const;
484110c101c3d0dd8dbc44c8d2d0edd3e2e7d6652fMarco Nelissen        virtual status_t        getPosition(uint32_t *position) const;
494110c101c3d0dd8dbc44c8d2d0edd3e2e7d6652fMarco Nelissen        virtual status_t        getFramesWritten(uint32_t*) const;
504110c101c3d0dd8dbc44c8d2d0edd3e2e7d6652fMarco Nelissen        virtual int             getSessionId() const;
519969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
529969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual status_t        open(
538162c1a9f4df4bf4733e78f5b03398b2991ba79aJean-Michel Trivi                uint32_t sampleRate, int channelCount, audio_channel_mask_t channelMask,
548dcbd11c186e26b67de813adaec66dd578415cd7Glenn Kasten                audio_format_t format, int bufferCount,
551948eb3ea6eee336e8cdab9b0c693f93f5f19993Eric Laurent                AudioCallback cb, void *cookie, audio_output_flags_t flags);
569969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
579969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual void            start();
589969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual ssize_t         write(const void* buffer, size_t size);
599969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual void            stop();
609969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual void            flush();
619969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual void            pause();
629969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual void            close();
63813c1017a499d5fe7a9ee7f40aae845954a3ba55Glenn Kasten        void setAudioStreamType(audio_stream_type_t streamType) { mStreamType = streamType; }
649969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang                void            setVolume(float left, float right);
659969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        virtual status_t        dump(int fd,const Vector<String16>& args) const;
669969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
679969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        static bool             isOnEmulator();
689969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        static int              getMinBufferCount();
699969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    private:
709969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        static void             setMinBufferCount();
719969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        static void             CallbackWrapper(
729969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang                int event, void *me, void *info);
739969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
749969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        AudioTrack*             mTrack;
759969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        AudioCallback           mCallback;
769969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        void *                  mCallbackCookie;
77813c1017a499d5fe7a9ee7f40aae845954a3ba55Glenn Kasten        audio_stream_type_t     mStreamType;
789969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        float                   mLeftVolume;
799969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        float                   mRightVolume;
809969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        float                   mMsecsPerFrame;
819969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        uint32_t                mLatency;
829969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        int                     mSessionId;
839969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        static bool             mIsOnEmulator;
849969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        static int              mMinBufferCount; // 12 for emulator; otherwise 4
859969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
869969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        public:
879969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        uint32_t                mNumFramesWritten;
889969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang        void                    snoopWrite(const void*, size_t);
899969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    };
909969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
919969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Changpublic:
9243fcc396614a587851e2b7c4cea2876ec58b8648Chih-Chung Chang    VideoEditorPlayer(NativeWindowRenderer* renderer);
939969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual ~VideoEditorPlayer();
949969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
959969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t initCheck();
969969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
979969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setDataSource(
989969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang            const char *url, const KeyedVector<String8, String8> *headers);
999969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1009969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
1019969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setVideoSurface(const sp<Surface> &surface);
1029969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
1039969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t prepare();
1049969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t prepareAsync();
1059969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t start();
1069969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t stop();
1079969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t pause();
1089969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual bool isPlaying();
1099969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t seekTo(int msec);
1109969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t getCurrentPosition(int *msec);
1119969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t getDuration(int *msec);
1129969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t reset();
1139969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setLooping(int loop);
1149969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual player_type playerType();
1159969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t invoke(const Parcel &request, Parcel *reply);
1169969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual void setAudioSink(const sp<AudioSink> &audioSink);
117fa31daff175709d2c58d61d1354daa9495696631Raghavender Palla    virtual void acquireLock();
1189969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual void releaseLock();
119acb62af8ccf493b38decd91d94eb18395b6f9461Gloria Wang    virtual status_t setParameter(int key, const Parcel &request);
120acb62af8ccf493b38decd91d94eb18395b6f9461Gloria Wang    virtual status_t getParameter(int key, Parcel *reply);
121fa31daff175709d2c58d61d1354daa9495696631Raghavender Palla
1229969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t getMetadata(
1239969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang                        const media::Metadata::Filter& ids, Parcel *records);
1249969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1259969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t loadEffectsSettings(
1269969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang                         M4VSS3GPP_EffectSettings* pEffectSettings, int nEffects);
1279969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1289969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t loadAudioMixSettings(
1299969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang                         M4xVSS_AudioMixingSettings* pAudioMixSettings);
1309969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1319969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setAudioMixPCMFileHandle(
1329969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang                         M4OSA_Context pAudioMixPCMFileHandle);
1339969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1349969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setAudioMixStoryBoardParam(
1359969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang                         M4OSA_UInt32 x, M4OSA_UInt32 y, M4OSA_UInt32 z);
1369969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1379969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setPlaybackBeginTime(uint32_t msec);
1389969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setPlaybackEndTime(uint32_t msec);
1399969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setStoryboardStartTime(uint32_t msec);
1409969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setProgressCallbackInterval(uint32_t cbInterval);
1419969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1429969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setMediaRenderingMode(M4xVSS_MediaRendering mode,
1439969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang                          M4VIDEOEDITING_VideoFrameSize outputVideoSize);
1449969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1459969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t resetJniCallbackTimeStamp();
1469969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t setImageClipProperties(uint32_t width, uint32_t height);
1479969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t readFirstVideoFrame();
1489969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    virtual status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs);
1499969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1509969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    status_t setAudioPlayer(VideoEditorAudioPlayer *audioPlayer);
1519969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Changprivate:
1529969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    PreviewPlayer       *mPlayer;
1539969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    sp<VeAudioOutput>    mVeAudioSink;
1549969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1559969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    VideoEditorPlayer(const VideoEditorPlayer &);
1569969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang    VideoEditorPlayer &operator=(const VideoEditorPlayer &);
1579969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang};
1589969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1599969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang}  // namespace android
1609969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang
1619969866cfe5b17c6e481b90d81b011a0cece78a0Chih-Chung Chang#endif  // ANDROID_VIDEOEDITOR_PLAYER_H
162