AwesomePlayer.h revision 42c5ae81036d4002da3fe1e3b1016131ba737e74
1bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber/*
2bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber * Copyright (C) 2009 The Android Open Source Project
3bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber *
4bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber * you may not use this file except in compliance with the License.
6bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber * You may obtain a copy of the License at
7bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber *
8bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
9bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber *
10bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber * Unless required by applicable law or agreed to in writing, software
11bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber * See the License for the specific language governing permissions and
14bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber * limitations under the License.
15bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber */
16bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
17bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber#ifndef AWESOME_PLAYER_H_
18bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
19bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber#define AWESOME_PLAYER_H_
20bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
211156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber#include "HTTPBase.h"
22bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber#include "TimedEventQueue.h"
23bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
24bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber#include <media/MediaPlayerInterface.h>
25fa090f541bb84a546af2ec834e91a032ff10e66eAndreas Huber#include <media/stagefright/DataSource.h>
26bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber#include <media/stagefright/OMXClient.h>
275d2de4da54504836e4b772b3010ac28c19f667f0Andreas Huber#include <media/stagefright/TimeSource.h>
28ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald#include <media/stagefright/MetaData.h>
29bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber#include <utils/threads.h>
30dcd25efb46c41c8d24a0a9cf61fb57f84149709eGloria Wang#include <drm/DrmManagerClient.h>
31bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
32bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Hubernamespace android {
33bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
3466b0a35c9a4136a84c3f73b1b25fcb5220138b95Andreas Huberstruct AudioPlayer;
357b3396acc702451be9bafb19d7fe26d55d43a316Andreas Huberstruct DataSource;
36bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huberstruct MediaBuffer;
37bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huberstruct MediaExtractor;
38bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huberstruct MediaSource;
390a5baa9b411fe086013d2a5e9126ed63fbad046cAndreas Huberstruct NuCachedSource2;
408ba01021b573889802e67e029225a96f0dfa471aAndy McFaddenstruct IGraphicBufferProducer;
41bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
42dcd25efb46c41c8d24a0a9cf61fb57f84149709eGloria Wangclass DrmManagerClinet;
43dcd25efb46c41c8d24a0a9cf61fb57f84149709eGloria Wangclass DecryptHandle;
44bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
456655174826330afe66ef766258181ae8c11f3f6cInsun Kangclass TimedTextDriver;
46681755fc0d0797506456f46a2a10555916d6be32Andreas Huberstruct WVMExtractor;
477a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang
48733b7729ea462fae9c6899456444e28fef1c757cAndreas Huberstruct AwesomeRenderer : public RefBase {
49733b7729ea462fae9c6899456444e28fef1c757cAndreas Huber    AwesomeRenderer() {}
50733b7729ea462fae9c6899456444e28fef1c757cAndreas Huber
51733b7729ea462fae9c6899456444e28fef1c757cAndreas Huber    virtual void render(MediaBuffer *buffer) = 0;
52733b7729ea462fae9c6899456444e28fef1c757cAndreas Huber
53733b7729ea462fae9c6899456444e28fef1c757cAndreas Huberprivate:
54733b7729ea462fae9c6899456444e28fef1c757cAndreas Huber    AwesomeRenderer(const AwesomeRenderer &);
55733b7729ea462fae9c6899456444e28fef1c757cAndreas Huber    AwesomeRenderer &operator=(const AwesomeRenderer &);
56733b7729ea462fae9c6899456444e28fef1c757cAndreas Huber};
57733b7729ea462fae9c6899456444e28fef1c757cAndreas Huber
58bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huberstruct AwesomePlayer {
59bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    AwesomePlayer();
60bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    ~AwesomePlayer();
61bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
620726045216f576e97672ebeefc265d39c4ebaaa5Andreas Huber    void setListener(const wp<MediaPlayerBase> &listener);
639b80c2bdb205bc143104f54d0743b6eedd67b14eAndreas Huber    void setUID(uid_t uid);
64bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
655561ccf4a8db88a2e44eac1b3ed13b4ff53a7f20Andreas Huber    status_t setDataSource(
665561ccf4a8db88a2e44eac1b3ed13b4ff53a7f20Andreas Huber            const char *uri,
675561ccf4a8db88a2e44eac1b3ed13b4ff53a7f20Andreas Huber            const KeyedVector<String8, String8> *headers = NULL);
685561ccf4a8db88a2e44eac1b3ed13b4ff53a7f20Andreas Huber
69bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    status_t setDataSource(int fd, int64_t offset, int64_t length);
70bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
71e2b1028852120bcfded33b8f06f66b780437fe92Andreas Huber    status_t setDataSource(const sp<IStreamSource> &source);
72e2b1028852120bcfded33b8f06f66b780437fe92Andreas Huber
73bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    void reset();
74bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
75c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber    status_t prepare();
76bd22c52280179b29eefac91ef7e7bbbc33d25904Andreas Huber    status_t prepare_l();
77c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber    status_t prepareAsync();
78c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber    status_t prepareAsync_l();
79c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber
80bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    status_t play();
81bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    status_t pause();
82bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
83bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    bool isPlaying() const;
84bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
858ba01021b573889802e67e029225a96f0dfa471aAndy McFadden    status_t setSurfaceTexture(const sp<IGraphicBufferProducer> &bufferProducer);
86bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    void setAudioSink(const sp<MediaPlayerBase::AudioSink> &audioSink);
87bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    status_t setLooping(bool shouldLoop);
88bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
89bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    status_t getDuration(int64_t *durationUs);
90bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    status_t getPosition(int64_t *positionUs);
91bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
924f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    status_t setParameter(int key, const Parcel &request);
934f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    status_t getParameter(int key, Parcel *reply);
94f9d660a5e0196240add5daf0199f128d471e592cInsun Kang    status_t invoke(const Parcel &request, Parcel *reply);
955b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong    status_t setCacheStatCollectFreq(const Parcel &request);
964f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang
97bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    status_t seekTo(int64_t timeUs);
98bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
99acdd9d0f59c3d8bdc3de80664a609527ec3d21e2Andreas Huber    // This is a mask of MediaExtractor::Flags.
100acdd9d0f59c3d8bdc3de80664a609527ec3d21e2Andreas Huber    uint32_t flags() const;
101acdd9d0f59c3d8bdc3de80664a609527ec3d21e2Andreas Huber
10284b343f29063fbfa2ee61b2e3d37ba059ca507d4Andreas Huber    void postAudioEOS(int64_t delayUs = 0ll);
103ed54ad0f8619ae416b0968ade6248894cbfc4dbaAndreas Huber    void postAudioSeekComplete();
104ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald    void postAudioTearDown();
105a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    status_t dump(int fd, const Vector<String16> &args) const;
106a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber
107bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huberprivate:
108bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    friend struct AwesomeEvent;
109ccb3506ed1845121b94f4e27244e61a46eb19815Dharmaray Kundargi    friend struct PreviewPlayer;
110bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
111acdd9d0f59c3d8bdc3de80664a609527ec3d21e2Andreas Huber    enum {
1127a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        PLAYING             = 0x01,
1137a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        LOOPING             = 0x02,
1147a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        FIRST_FRAME         = 0x04,
1157a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        PREPARING           = 0x08,
1167a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        PREPARED            = 0x10,
1177a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        AT_EOS              = 0x20,
1187a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        PREPARE_CANCELLED   = 0x40,
1197a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        CACHE_UNDERRUN      = 0x80,
1207a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        AUDIO_AT_EOS        = 0x0100,
1217a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        VIDEO_AT_EOS        = 0x0200,
1227a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        AUTO_LOOPING        = 0x0400,
1236a05c9e912aeb8bfe1ef99516def91a177a481b6Andreas Huber
1246a05c9e912aeb8bfe1ef99516def91a177a481b6Andreas Huber        // We are basically done preparing but are currently buffering
1256a05c9e912aeb8bfe1ef99516def91a177a481b6Andreas Huber        // sufficient data to begin playback and finish the preparation phase
1266a05c9e912aeb8bfe1ef99516def91a177a481b6Andreas Huber        // for good.
1277a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        PREPARING_CONNECTED = 0x0800,
1282b1222f8938356669672f35e0e53e176c78c40efAndreas Huber
1292b1222f8938356669672f35e0e53e176c78c40efAndreas Huber        // We're triggering a single video event to display the first frame
1302b1222f8938356669672f35e0e53e176c78c40efAndreas Huber        // after the seekpoint.
1317a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        SEEK_PREVIEW        = 0x1000,
132f03034408506051f2f836e59305fcd5f662bf19aAndreas Huber
1337a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        AUDIO_RUNNING       = 0x2000,
1347a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        AUDIOPLAYER_STARTED = 0x4000,
1357314fa17093d514199fedcb55ac41136a1b31cb3Andreas Huber
1367a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        INCOGNITO           = 0x8000,
1377a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang
1387a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang        TEXT_RUNNING        = 0x10000,
139f9d660a5e0196240add5daf0199f128d471e592cInsun Kang        TEXTPLAYER_INITIALIZED  = 0x20000,
14014f95746466fb6abdbbf33ee26d92ebf3fbef98fJames Dong
14114f95746466fb6abdbbf33ee26d92ebf3fbef98fJames Dong        SLOW_DECODER_HACK   = 0x40000,
142bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    };
143bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
144bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    mutable Mutex mLock;
1452415ecb5bb4e1459024f6d6c8ae2d6e3dc4fbdc7Andreas Huber    Mutex mMiscStateLock;
146a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    mutable Mutex mStatsLock;
14702f6e988107bc13ebe4828b734ea0fc3d9d11ae0Andreas Huber    Mutex mAudioLock;
148bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
149bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    OMXClient mClient;
150bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    TimedEventQueue mQueue;
1512e8ffaf95bd35358ecd14ddf00cddaf3abefe0a9Andreas Huber    bool mQueueStarted;
1520726045216f576e97672ebeefc265d39c4ebaaa5Andreas Huber    wp<MediaPlayerBase> mListener;
1539b80c2bdb205bc143104f54d0743b6eedd67b14eAndreas Huber    bool mUIDValid;
1549b80c2bdb205bc143104f54d0743b6eedd67b14eAndreas Huber    uid_t mUID;
155bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
1561173118eace0e9e347cb007f0da817cee87579edGlenn Kasten    sp<ANativeWindow> mNativeWindow;
157bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    sp<MediaPlayerBase::AudioSink> mAudioSink;
158bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
1595d2de4da54504836e4b772b3010ac28c19f667f0Andreas Huber    SystemTimeSource mSystemTimeSource;
160bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    TimeSource *mTimeSource;
161bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
162bd22c52280179b29eefac91ef7e7bbbc33d25904Andreas Huber    String8 mUri;
163bd22c52280179b29eefac91ef7e7bbbc33d25904Andreas Huber    KeyedVector<String8, String8> mUriHeaders;
164bd22c52280179b29eefac91ef7e7bbbc33d25904Andreas Huber
1657b3396acc702451be9bafb19d7fe26d55d43a316Andreas Huber    sp<DataSource> mFileSource;
1667b3396acc702451be9bafb19d7fe26d55d43a316Andreas Huber
16788d8a83de12592635248aa1a3bd6b9ea46108501Andreas Huber    sp<MediaSource> mVideoTrack;
168bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    sp<MediaSource> mVideoSource;
169733b7729ea462fae9c6899456444e28fef1c757cAndreas Huber    sp<AwesomeRenderer> mVideoRenderer;
170c374dae535b83d9b499dd9fe8f9dabdb8b0ac9fdJames Dong    bool mVideoRenderingStarted;
171fa090f541bb84a546af2ec834e91a032ff10e66eAndreas Huber    bool mVideoRendererIsPreview;
172cbaffcffee6418d678806e63097c19fe26d48fe0Lajos Molnar    int32_t mMediaRenderingStartGeneration;
173cbaffcffee6418d678806e63097c19fe26d48fe0Lajos Molnar    int32_t mStartGeneration;
174bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
175ab7a2e544643edcb2e09ed5f204580afd763edc1James Dong    ssize_t mActiveAudioTrackIndex;
17688d8a83de12592635248aa1a3bd6b9ea46108501Andreas Huber    sp<MediaSource> mAudioTrack;
177ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald    sp<MediaSource> mOmxSource;
178bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    sp<MediaSource> mAudioSource;
179bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    AudioPlayer *mAudioPlayer;
180bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    int64_t mDurationUs;
181bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
182b45c01c2b8588ff431b511151666a55a39f0a6aeJames Dong    int32_t mDisplayWidth;
183b45c01c2b8588ff431b511151666a55a39f0a6aeJames Dong    int32_t mDisplayHeight;
1844f6eed0d1c7972a983c075bdcf03089569e13fe1James Dong    int32_t mVideoScalingMode;
185b45c01c2b8588ff431b511151666a55a39f0a6aeJames Dong
186bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    uint32_t mFlags;
187acdd9d0f59c3d8bdc3de80664a609527ec3d21e2Andreas Huber    uint32_t mExtractorFlags;
18814f95746466fb6abdbbf33ee26d92ebf3fbef98fJames Dong    uint32_t mSinceLastDropped;
189bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
190bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    int64_t mTimeSourceDeltaUs;
191bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    int64_t mVideoTimeUs;
192bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
19364bb6983690bf994d904591145a3cdd6373bdbe6Andreas Huber    enum SeekType {
19464bb6983690bf994d904591145a3cdd6373bdbe6Andreas Huber        NO_SEEK,
19564bb6983690bf994d904591145a3cdd6373bdbe6Andreas Huber        SEEK,
19664bb6983690bf994d904591145a3cdd6373bdbe6Andreas Huber        SEEK_VIDEO_ONLY
19764bb6983690bf994d904591145a3cdd6373bdbe6Andreas Huber    };
19864bb6983690bf994d904591145a3cdd6373bdbe6Andreas Huber    SeekType mSeeking;
19964bb6983690bf994d904591145a3cdd6373bdbe6Andreas Huber
2001321fdd94d354431b930735e9f38f32ecd189a2dAndreas Huber    bool mSeekNotificationSent;
201bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    int64_t mSeekTimeUs;
202bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
2037fbdb0903dfbf70b314a74e64e28fb880cdb9247Andreas Huber    int64_t mBitrate;  // total bitrate of the file (in bps) or -1 if unknown.
2047fbdb0903dfbf70b314a74e64e28fb880cdb9247Andreas Huber
2051862a33b246249630b654182afb5914da3480d4cAndreas Huber    bool mWatchForAudioSeekComplete;
2061862a33b246249630b654182afb5914da3480d4cAndreas Huber    bool mWatchForAudioEOS;
2071862a33b246249630b654182afb5914da3480d4cAndreas Huber
208bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    sp<TimedEventQueue::Event> mVideoEvent;
209bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    bool mVideoEventPending;
210bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    sp<TimedEventQueue::Event> mStreamDoneEvent;
211bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    bool mStreamDoneEventPending;
21266b0a35c9a4136a84c3f73b1b25fcb5220138b95Andreas Huber    sp<TimedEventQueue::Event> mBufferingEvent;
21366b0a35c9a4136a84c3f73b1b25fcb5220138b95Andreas Huber    bool mBufferingEventPending;
2141862a33b246249630b654182afb5914da3480d4cAndreas Huber    sp<TimedEventQueue::Event> mCheckAudioStatusEvent;
2151862a33b246249630b654182afb5914da3480d4cAndreas Huber    bool mAudioStatusEventPending;
216145e68fc778275963189b02a1adcbe27cce4d769Andreas Huber    sp<TimedEventQueue::Event> mVideoLagEvent;
217145e68fc778275963189b02a1adcbe27cce4d769Andreas Huber    bool mVideoLagEventPending;
218ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald    sp<TimedEventQueue::Event> mAudioTearDownEvent;
219ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald    bool mAudioTearDownEventPending;
220c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber    sp<TimedEventQueue::Event> mAsyncPrepareEvent;
221c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber    Condition mPreparedCondition;
222bd22c52280179b29eefac91ef7e7bbbc33d25904Andreas Huber    bool mIsAsyncPrepare;
223bd22c52280179b29eefac91ef7e7bbbc33d25904Andreas Huber    status_t mPrepareResult;
2245295c0c55d41a2906ea7f65a3f22e6278cb17d4bAndreas Huber    status_t mStreamDoneStatus;
225c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber
226bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    void postVideoEvent_l(int64_t delayUs = -1);
22766b0a35c9a4136a84c3f73b1b25fcb5220138b95Andreas Huber    void postBufferingEvent_l();
2285295c0c55d41a2906ea7f65a3f22e6278cb17d4bAndreas Huber    void postStreamDoneEvent_l(status_t status);
22902f6e988107bc13ebe4828b734ea0fc3d9d11ae0Andreas Huber    void postCheckAudioStatusEvent(int64_t delayUs);
230145e68fc778275963189b02a1adcbe27cce4d769Andreas Huber    void postVideoLagEvent_l();
23194ea60f975c3eb7ce6d2a4430538a42a5fc3babdRichard Fitzgerald    void postAudioTearDownEvent(int64_t delayUs);
232ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald
2337b3396acc702451be9bafb19d7fe26d55d43a316Andreas Huber    status_t play_l();
234bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
235bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    MediaBuffer *mVideoBuffer;
236bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
2371156dc913a5ba7b2bc86489468d4914430f03d14Andreas Huber    sp<HTTPBase> mConnectingDataSource;
2380a5baa9b411fe086013d2a5e9126ed63fbad046cAndreas Huber    sp<NuCachedSource2> mCachedSource;
23966b0a35c9a4136a84c3f73b1b25fcb5220138b95Andreas Huber
240dcd25efb46c41c8d24a0a9cf61fb57f84149709eGloria Wang    DrmManagerClient *mDrmManagerClient;
241b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang    sp<DecryptHandle> mDecryptHandle;
242dcd25efb46c41c8d24a0a9cf61fb57f84149709eGloria Wang
243150694cda0842d38a9358fe8d1fcb4fb4a76599eAndreas Huber    int64_t mLastVideoTimeUs;
2446655174826330afe66ef766258181ae8c11f3f6cInsun Kang    TimedTextDriver *mTextDriver;
245150694cda0842d38a9358fe8d1fcb4fb4a76599eAndreas Huber
246681755fc0d0797506456f46a2a10555916d6be32Andreas Huber    sp<WVMExtractor> mWVMExtractor;
247eec46abb88dcc50621fd2d3f17a6b8d24fd07a19James Dong    sp<MediaExtractor> mExtractor;
248681755fc0d0797506456f46a2a10555916d6be32Andreas Huber
2497b3396acc702451be9bafb19d7fe26d55d43a316Andreas Huber    status_t setDataSource_l(
2507b3396acc702451be9bafb19d7fe26d55d43a316Andreas Huber            const char *uri,
2517b3396acc702451be9bafb19d7fe26d55d43a316Andreas Huber            const KeyedVector<String8, String8> *headers = NULL);
2527b3396acc702451be9bafb19d7fe26d55d43a316Andreas Huber
2537b3396acc702451be9bafb19d7fe26d55d43a316Andreas Huber    status_t setDataSource_l(const sp<DataSource> &dataSource);
254bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    status_t setDataSource_l(const sp<MediaExtractor> &extractor);
255bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    void reset_l();
256bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    status_t seekTo_l(int64_t timeUs);
257b2e3954c94717e43b3dc9b880564f166cfbbc0a2Andreas Huber    status_t pause_l(bool at_eos = false);
258bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    void initRenderer_l();
2595daeb129a2c2ba3d14ccd94af283b5f561c783eaAndreas Huber    void notifyVideoSize_l();
260bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    void seekAudioIfNecessary_l();
261bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
262c34233e673c9791e137456d0c427d58db184b690Andreas Huber    void cancelPlayerEvents(bool keepNotifications = false);
263bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
26488d8a83de12592635248aa1a3bd6b9ea46108501Andreas Huber    void setAudioSource(sp<MediaSource> source);
26588d8a83de12592635248aa1a3bd6b9ea46108501Andreas Huber    status_t initAudioDecoder();
26688d8a83de12592635248aa1a3bd6b9ea46108501Andreas Huber
267ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald
26888d8a83de12592635248aa1a3bd6b9ea46108501Andreas Huber    void setVideoSource(sp<MediaSource> source);
2692a4d22d79e927f2245537921e10fc5fda1c47a29Andreas Huber    status_t initVideoDecoder(uint32_t flags = 0);
270bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
2716a3969cc3bcbfc84dbcc27aa726eb96bc03a830bEdwin Wong    void addTextSource_l(size_t trackIndex, const sp<MediaSource>& source);
2727a1e3e81264189e23a1db2b174e1b5a5d4c7d1c3Gloria Wang
273bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    void onStreamDone();
274bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
275c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber    void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0);
27666b0a35c9a4136a84c3f73b1b25fcb5220138b95Andreas Huber
277c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber    void onVideoEvent();
27866b0a35c9a4136a84c3f73b1b25fcb5220138b95Andreas Huber    void onBufferingUpdate();
2791862a33b246249630b654182afb5914da3480d4cAndreas Huber    void onCheckAudioStatus();
280c23f12af0394aa2f6651968a3c8840f1af317aa1Andreas Huber    void onPrepareAsyncEvent();
28188d8a83de12592635248aa1a3bd6b9ea46108501Andreas Huber    void abortPrepare(status_t err);
2828650e1960905097f6f1d6aa462ccb1c93c656834Andreas Huber    void finishAsyncPrepare_l();
283145e68fc778275963189b02a1adcbe27cce4d769Andreas Huber    void onVideoLagUpdate();
284ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald    void onAudioTearDownEvent();
285ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald
286ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald    void beginPrepareAsync_l();
2878650e1960905097f6f1d6aa462ccb1c93c656834Andreas Huber
2888650e1960905097f6f1d6aa462ccb1c93c656834Andreas Huber    bool getCachedDuration_l(int64_t *durationUs, bool *eos);
28988d8a83de12592635248aa1a3bd6b9ea46108501Andreas Huber
290bd22c52280179b29eefac91ef7e7bbbc33d25904Andreas Huber    status_t finishSetDataSource_l();
2910726045216f576e97672ebeefc265d39c4ebaaa5Andreas Huber
292e966fb05c7e67a7f5dce65024de60aac83eb6f81Andreas Huber    static bool ContinuePreparation(void *cookie);
293e966fb05c7e67a7f5dce65024de60aac83eb6f81Andreas Huber
2947fbdb0903dfbf70b314a74e64e28fb880cdb9247Andreas Huber    bool getBitrate(int64_t *bitrate);
2957fbdb0903dfbf70b314a74e64e28fb880cdb9247Andreas Huber
2964769cc92740e3ab58e9263d42553c12bbf79e3beAndreas Huber    void finishSeekIfNecessary(int64_t videoTimeUs);
29734ef0f32c8fc0186236a27e07405328cc1f7c56dAndreas Huber    void ensureCacheIsFetching_l();
2984769cc92740e3ab58e9263d42553c12bbf79e3beAndreas Huber
299cbaffcffee6418d678806e63097c19fe26d48fe0Lajos Molnar    void notifyIfMediaStarted_l();
300ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald    void createAudioPlayer_l();
3015442cb59e8483e18b3a02400d431d167ea7074b3Andreas Huber    status_t startAudioPlayer_l(bool sendErrorNotification = true);
302f03034408506051f2f836e59305fcd5f662bf19aAndreas Huber
303150694cda0842d38a9358fe8d1fcb4fb4a76599eAndreas Huber    void shutdownVideoDecoder_l();
30463970b42f101c87db7cfd26d43b0d300260b1582Andreas Huber    status_t setNativeWindow_l(const sp<ANativeWindow> &native);
305150694cda0842d38a9358fe8d1fcb4fb4a76599eAndreas Huber
306681755fc0d0797506456f46a2a10555916d6be32Andreas Huber    bool isStreamingHTTP() const;
3075b1b8a93a07326f1cbc627f09e02988375189e0aJames Dong    void sendCacheStats();
3089d2f386dd2885eaffa11fd494ae258bb09fe6397James Dong    void checkDrmStatus(const sp<DataSource>& dataSource);
309681755fc0d0797506456f46a2a10555916d6be32Andreas Huber
310a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    enum FlagMode {
311a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        SET,
312a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        CLEAR,
313a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        ASSIGN
314a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    };
315a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    void modifyFlags(unsigned value, FlagMode mode);
316a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber
317a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    struct TrackStat {
318a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        String8 mMIME;
319a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        String8 mDecoderName;
320a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    };
321a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber
322a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    // protected by mStatsLock
323a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    struct Stats {
324a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        int mFd;
325a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        String8 mURI;
326a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        int64_t mBitrate;
327ab7a2e544643edcb2e09ed5f204580afd763edc1James Dong
328ab7a2e544643edcb2e09ed5f204580afd763edc1James Dong        // FIXME:
329ab7a2e544643edcb2e09ed5f204580afd763edc1James Dong        // These two indices are just 0 or 1 for now
330ab7a2e544643edcb2e09ed5f204580afd763edc1James Dong        // They are not representing the actual track
331ab7a2e544643edcb2e09ed5f204580afd763edc1James Dong        // indices in the stream.
332a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        ssize_t mAudioTrackIndex;
333a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        ssize_t mVideoTrackIndex;
334ab7a2e544643edcb2e09ed5f204580afd763edc1James Dong
335a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        int64_t mNumVideoFramesDecoded;
336a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        int64_t mNumVideoFramesDropped;
337a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        int32_t mVideoWidth;
338a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        int32_t mVideoHeight;
339a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        uint32_t mFlags;
340a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber        Vector<TrackStat> mTracks;
341a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber    } mStats;
342a0b1d4b161599c2bb2a47119e50c51e75bbe980eAndreas Huber
343ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald    bool    mOffloadAudio;
344ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald    bool    mAudioTearDown;
34542c5ae81036d4002da3fe1e3b1016131ba737e74Marco Nelissen    bool    mAudioTearDownWasPlaying;
34642c5ae81036d4002da3fe1e3b1016131ba737e74Marco Nelissen    int64_t mAudioTearDownPosition;
347ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald
3484f6eed0d1c7972a983c075bdcf03089569e13fe1James Dong    status_t setVideoScalingMode(int32_t mode);
3494f6eed0d1c7972a983c075bdcf03089569e13fe1James Dong    status_t setVideoScalingMode_l(int32_t mode);
350eec46abb88dcc50621fd2d3f17a6b8d24fd07a19James Dong    status_t getTrackInfo(Parcel* reply) const;
351eec46abb88dcc50621fd2d3f17a6b8d24fd07a19James Dong
352ab7a2e544643edcb2e09ed5f204580afd763edc1James Dong    status_t selectAudioTrack_l(const sp<MediaSource>& source, size_t trackIndex);
353ab7a2e544643edcb2e09ed5f204580afd763edc1James Dong
354eec46abb88dcc50621fd2d3f17a6b8d24fd07a19James Dong    // when select is true, the given track is selected.
355eec46abb88dcc50621fd2d3f17a6b8d24fd07a19James Dong    // otherwise, the given track is unselected.
356eec46abb88dcc50621fd2d3f17a6b8d24fd07a19James Dong    status_t selectTrack(size_t trackIndex, bool select);
357eec46abb88dcc50621fd2d3f17a6b8d24fd07a19James Dong
358eec46abb88dcc50621fd2d3f17a6b8d24fd07a19James Dong    size_t countTracks() const;
359eec46abb88dcc50621fd2d3f17a6b8d24fd07a19James Dong
360bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    AwesomePlayer(const AwesomePlayer &);
361bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber    AwesomePlayer &operator=(const AwesomePlayer &);
362bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber};
363bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
364bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber}  // namespace android
365bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber
366bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huber#endif  // AWESOME_PLAYER_H_
367