NuPlayerRenderer.h revision f933441648ef6a71dee783d733aac17b9508b452
1/*
2 * Copyright (C) 2010 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 NUPLAYER_RENDERER_H_
18
19#define NUPLAYER_RENDERER_H_
20
21#include "NuPlayer.h"
22
23namespace android {
24
25struct NuPlayer::Renderer : public AHandler {
26    Renderer(const sp<MediaPlayerBase::AudioSink> &sink,
27             const sp<AMessage> &notify);
28
29    void queueBuffer(
30            bool audio,
31            const sp<ABuffer> &buffer,
32            const sp<AMessage> &notifyConsumed);
33
34    void queueEOS(bool audio, status_t finalResult);
35
36    void flush(bool audio);
37
38    void signalTimeDiscontinuity();
39
40    enum {
41        kWhatEOS,
42        kWhatFlushComplete,
43    };
44
45protected:
46    virtual ~Renderer();
47
48    virtual void onMessageReceived(const sp<AMessage> &msg);
49
50private:
51    enum {
52        kWhatDrainAudioQueue,
53        kWhatDrainVideoQueue,
54        kWhatQueueBuffer,
55        kWhatQueueEOS,
56        kWhatFlush,
57    };
58
59    struct QueueEntry {
60        sp<ABuffer> mBuffer;
61        sp<AMessage> mNotifyConsumed;
62        size_t mOffset;
63        status_t mFinalResult;
64    };
65
66    sp<MediaPlayerBase::AudioSink> mAudioSink;
67    sp<AMessage> mNotify;
68    List<QueueEntry> mAudioQueue;
69    List<QueueEntry> mVideoQueue;
70    uint32_t mNumFramesWritten;
71
72    bool mDrainAudioQueuePending;
73    bool mDrainVideoQueuePending;
74    int32_t mAudioQueueGeneration;
75    int32_t mVideoQueueGeneration;
76
77    int64_t mAnchorTimeMediaUs;
78    int64_t mAnchorTimeRealUs;
79
80    Mutex mFlushLock;  // protects the following 2 member vars.
81    bool mFlushingAudio;
82    bool mFlushingVideo;
83
84    bool mSyncQueues;
85
86    void onDrainAudioQueue();
87    void postDrainAudioQueue();
88
89    void onDrainVideoQueue();
90    void postDrainVideoQueue();
91
92    void onQueueBuffer(const sp<AMessage> &msg);
93    void onQueueEOS(const sp<AMessage> &msg);
94    void onFlush(const sp<AMessage> &msg);
95
96    void notifyEOS(bool audio);
97    void notifyFlushComplete(bool audio);
98
99    void flushQueue(List<QueueEntry> *queue);
100    bool dropBufferWhileFlushing(bool audio, const sp<AMessage> &msg);
101    void syncQueuesDone();
102
103    DISALLOW_EVIL_CONSTRUCTORS(Renderer);
104};
105
106}  // namespace android
107
108#endif  // NUPLAYER_RENDERER_H_
109