forked from esrlabs/AndroidTransporterPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPiPlayer.h
106 lines (92 loc) · 3.15 KB
/
RPiPlayer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (C) 2012 E.S.R.Labs GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RPIPLAYER_H_
#define RPIPLAYER_H_
#include <mindroid/os/LooperThread.h>
#include <mindroid/lang/String.h>
#include <mindroid/util/List.h>
#include "NetHandler.h"
extern "C" {
#include "bcm_host.h"
#include "ilclient.h"
}
namespace mindroid {
class Buffer;
}
using mindroid::sp;
class RPiPlayer :
public mindroid::Handler
{
public:
static const uint32_t NOTIFY_QUEUE_AUDIO_BUFFER = 1;
static const uint32_t NOTIFY_QUEUE_VIDEO_BUFFER = 2;
static const uint32_t NOTIFY_PLAY_AUDIO_BUFFER = 3;
static const uint32_t NOTIFY_PLAY_VIDEO_BUFFER = 4;
static const uint32_t STOP_MEDIA_SOURCE_DONE = 5;
static const uint32_t NOTIFY_AUDIO_OMX_EMPTY_BUFFER_DONE = 6;
RPiPlayer();
virtual ~RPiPlayer();
bool start(const sp<mindroid::String>& url);
void stop();
virtual void handleMessage(const sp<mindroid::Message>& message);
private:
bool startMediaSource(const sp<mindroid::String>& url);
void stopMediaSource();
int initOMXAudio();
bool setAudioSink(const char* sinkName);
void finalizeOMXAudio();
int initOMXVideo();
void finalizeOMXVideo();
void onPlayAudioBuffers();
void onFillAndPlayAudioBuffers();
void onPlayVideoBuffers();
static void onEmptyBufferDone(void* args, COMPONENT_T* component);
uint32_t getAudioBufferSize();
bool minNumAudioSamplesAvailable();
void calcNumAudioStretchSamples();
uint32_t numOmxOwnedAudioSamples();
sp< mindroid::LooperThread<NetHandler> > mNetLooper;
sp< mindroid::List< sp<mindroid::Buffer> > > mAudioBuffers;
sp< mindroid::List< sp<mindroid::Buffer> > > mVideoBuffers;
// Audio
static const uint32_t SAMPLE_RATE = 43932; // Hz, should be 44100Hz but the RPi hardware is too fast.
static const uint32_t NUM_CHANNELS = 2;
static const uint32_t BITS_PER_SAMPLE = 16;
static const uint32_t BYTES_PER_SAMPLE = BITS_PER_SAMPLE / 8;
static const uint32_t NUM_OMX_AUDIO_BUFFERS = 8;
static const uint32_t OMX_AUDIO_BUFFER_SIZE = 4096; // 2048 samples -> 46ms
ILCLIENT_T* mAudioClient;
COMPONENT_T* mAudioRenderer;
COMPONENT_T* mAudioComponentList[2];
OMX_BUFFERHEADERTYPE* mOmxAudioBuffer;
bool mRebufferAudioData;
sp< mindroid::List< OMX_BUFFERHEADERTYPE* > > mOmxAudioInputBuffers;
sp< mindroid::List< OMX_BUFFERHEADERTYPE* > > mOmxAudioEmptyBuffers;
sp<mindroid::Buffer> mAudioBuffer;
size_t mNumAudioStretchSamples;
// Video
ILCLIENT_T* mVideoClient;
TUNNEL_T mTunnel[4];
COMPONENT_T* mVideoComponentList[5];
COMPONENT_T* mVideoDecoder;
COMPONENT_T* mVideoScheduler;
COMPONENT_T* mVideoRenderer;
COMPONENT_T* mClock;
bool mPortSettingsChanged;
bool mFirstVideoPacket;
bool mShutdown;
};
#endif /* RPIPLAYER_H_ */