1f933441648ef6a71dee783d733aac17b9508b452Andreas Huber/*
2f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * Copyright (C) 2010 The Android Open Source Project
3f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *
4f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * you may not use this file except in compliance with the License.
6f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * You may obtain a copy of the License at
7f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *
8f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
9f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *
10f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * Unless required by applicable law or agreed to in writing, software
11f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * See the License for the specific language governing permissions and
14f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * limitations under the License.
15f933441648ef6a71dee783d733aac17b9508b452Andreas Huber */
16f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
17f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#ifndef NU_PLAYER_H_
18f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
19f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#define NU_PLAYER_H_
20f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
21f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#include <media/MediaPlayerInterface.h>
22f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#include <media/stagefright/foundation/AHandler.h>
231173118eace0e9e347cb007f0da817cee87579edGlenn Kasten#include <media/stagefright/NativeWindowWrapper.h>
24f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
25f933441648ef6a71dee783d733aac17b9508b452Andreas Hubernamespace android {
26f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
27f933441648ef6a71dee783d733aac17b9508b452Andreas Huberstruct ACodec;
28f933441648ef6a71dee783d733aac17b9508b452Andreas Huberstruct MetaData;
2943c3e6ce02215ca99d506458f596cb1211639f29Andreas Huberstruct NuPlayerDriver;
30f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
31f933441648ef6a71dee783d733aac17b9508b452Andreas Huberstruct NuPlayer : public AHandler {
32f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    NuPlayer();
33f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
349b80c2bdb205bc143104f54d0743b6eedd67b14eAndreas Huber    void setUID(uid_t uid);
359b80c2bdb205bc143104f54d0743b6eedd67b14eAndreas Huber
3643c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    void setDriver(const wp<NuPlayerDriver> &driver);
37f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
38f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    void setDataSource(const sp<IStreamSource> &source);
395bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
405bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    void setDataSource(
415bc087c573c70c84c6a39946457590b42d392a33Andreas Huber            const char *url, const KeyedVector<String8, String8> *headers);
425bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
43afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    void setDataSource(int fd, int64_t offset, int64_t length);
44afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
451173118eace0e9e347cb007f0da817cee87579edGlenn Kasten    void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
46f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
47f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    void start();
48f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
4943c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    void pause();
5043c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    void resume();
5143c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber
5243c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    // Will notify the driver through "notifyResetComplete" once finished.
531aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    void resetAsync();
541aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber
5543c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    // Will notify the driver through "notifySeekComplete" once finished.
5643c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    void seekToAsync(int64_t seekTimeUs);
5743c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber
580d268a3cae145afb2720c88ae38fb81550be5584James Dong    status_t setVideoScalingMode(int32_t mode);
590d268a3cae145afb2720c88ae38fb81550be5584James Dong
60f933441648ef6a71dee783d733aac17b9508b452Andreas Huberprotected:
61f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual ~NuPlayer();
62f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
63f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual void onMessageReceived(const sp<AMessage> &msg);
64f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
65840667883fd09d44015716d79bc3ac4d60edc0f0Andreas Huberpublic:
66840667883fd09d44015716d79bc3ac4d60edc0f0Andreas Huber    struct NuPlayerStreamListener;
67840667883fd09d44015716d79bc3ac4d60edc0f0Andreas Huber    struct Source;
68840667883fd09d44015716d79bc3ac4d60edc0f0Andreas Huber
69f933441648ef6a71dee783d733aac17b9508b452Andreas Huberprivate:
70f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct Decoder;
71afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    struct GenericSource;
725bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    struct HTTPLiveSource;
735bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    struct Renderer;
74afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    struct RTSPSource;
755bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    struct StreamingSource;
76f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
77f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    enum {
78078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatSetDataSource              = '=DaS',
79078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatSetVideoNativeWindow       = '=NaW',
80078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatSetAudioSink               = '=AuS',
81078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatMoreDataQueued             = 'more',
82078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatStart                      = 'strt',
83078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatScanSources                = 'scan',
84078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatVideoNotify                = 'vidN',
85078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatAudioNotify                = 'audN',
86078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatRendererNotify             = 'renN',
87078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatReset                      = 'rset',
88078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatSeek                       = 'seek',
89078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatPause                      = 'paus',
90078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber        kWhatResume                     = 'rsme',
91f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    };
92f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
9343c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    wp<NuPlayerDriver> mDriver;
949b80c2bdb205bc143104f54d0743b6eedd67b14eAndreas Huber    bool mUIDValid;
959b80c2bdb205bc143104f54d0743b6eedd67b14eAndreas Huber    uid_t mUID;
965bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    sp<Source> mSource;
971173118eace0e9e347cb007f0da817cee87579edGlenn Kasten    sp<NativeWindowWrapper> mNativeWindow;
98f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<MediaPlayerBase::AudioSink> mAudioSink;
99f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<Decoder> mVideoDecoder;
1003fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber    bool mVideoIsAVC;
101f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<Decoder> mAudioDecoder;
102f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<Renderer> mRenderer;
103f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
104f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    bool mAudioEOS;
105f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    bool mVideoEOS;
106f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
1075bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    bool mScanSourcesPending;
1081aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    int32_t mScanSourcesGeneration;
1095bc087c573c70c84c6a39946457590b42d392a33Andreas Huber
110f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    enum FlushStatus {
111f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        NONE,
112f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        AWAITING_DISCONTINUITY,
113f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        FLUSHING_DECODER,
1141aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber        FLUSHING_DECODER_SHUTDOWN,
1153831a066bcf1019864a94d2bc7b4c9241efc5c22Andreas Huber        SHUTTING_DOWN_DECODER,
1163831a066bcf1019864a94d2bc7b4c9241efc5c22Andreas Huber        FLUSHED,
1173831a066bcf1019864a94d2bc7b4c9241efc5c22Andreas Huber        SHUT_DOWN,
118f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    };
119f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
1206e3d311b6631b12aac2879d1b08c3534aece78b1Andreas Huber    // Once the current flush is complete this indicates whether the
1216e3d311b6631b12aac2879d1b08c3534aece78b1Andreas Huber    // notion of time has changed.
1226e3d311b6631b12aac2879d1b08c3534aece78b1Andreas Huber    bool mTimeDiscontinuityPending;
1236e3d311b6631b12aac2879d1b08c3534aece78b1Andreas Huber
124f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    FlushStatus mFlushingAudio;
125f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    FlushStatus mFlushingVideo;
1261aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    bool mResetInProgress;
1271aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    bool mResetPostponed;
128f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
12932f3cefa373cd55e63deda36ca9d07c7fe22eaafAndreas Huber    int64_t mSkipRenderingAudioUntilMediaTimeUs;
13032f3cefa373cd55e63deda36ca9d07c7fe22eaafAndreas Huber    int64_t mSkipRenderingVideoUntilMediaTimeUs;
13132f3cefa373cd55e63deda36ca9d07c7fe22eaafAndreas Huber
1323fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber    int64_t mVideoLateByUs;
1333fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber    int64_t mNumFramesTotal, mNumFramesDropped;
1343fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber
1350d268a3cae145afb2720c88ae38fb81550be5584James Dong    int32_t mVideoScalingMode;
1360d268a3cae145afb2720c88ae38fb81550be5584James Dong
1375bc087c573c70c84c6a39946457590b42d392a33Andreas Huber    status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
138f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
139f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
140f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    void renderBuffer(bool audio, const sp<AMessage> &msg);
141f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
142f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    void notifyListener(int msg, int ext1, int ext2);
143f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
1443831a066bcf1019864a94d2bc7b4c9241efc5c22Andreas Huber    void finishFlushIfPossible();
1453831a066bcf1019864a94d2bc7b4c9241efc5c22Andreas Huber
1461aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    void flushDecoder(bool audio, bool needShutdown);
1471aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber
1481aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
1491aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber
1501aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    void finishReset();
1511aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    void postScanSources();
15253df1a460bcfdd129ca2bc416dee2009e35c042eAndreas Huber
153f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
154f933441648ef6a71dee783d733aac17b9508b452Andreas Huber};
155f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
156f933441648ef6a71dee783d733aac17b9508b452Andreas Huber}  // namespace android
157f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
158f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#endif  // NU_PLAYER_H_
159