Skip to content

Commit

Permalink
support switch primary device
Browse files Browse the repository at this point in the history
  • Loading branch information
zillevdr committed Feb 24, 2021
1 parent 63a1806 commit 4befc12
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 33 deletions.
30 changes: 16 additions & 14 deletions softhddev.c
Expand Up @@ -1716,21 +1716,23 @@ int Start(void)
#ifdef DEBUG
fprintf(stderr, "Start(void):\n");
#endif
AudioInit();
av_new_packet(AudioAvPkt, AUDIO_BUFFER_SIZE);
MyAudioDecoder = CodecAudioNewDecoder();
AudioCodecID = AV_CODEC_ID_NONE;
AudioChannelID = -1;

CodecInit();
if (!MyVideoStream->Decoder) {
MyVideoStream->CodecID = AV_CODEC_ID_NONE;
}
if (!MyAudioDecoder) {
AudioInit();
av_new_packet(AudioAvPkt, AUDIO_BUFFER_SIZE);
MyAudioDecoder = CodecAudioNewDecoder();
AudioCodecID = AV_CODEC_ID_NONE;
AudioChannelID = -1;

if ((MyVideoStream->Render = VideoNewRender(MyVideoStream))) {
VideoInit(MyVideoStream->Render);
MyVideoStream->Decoder = CodecVideoNewDecoder(MyVideoStream->Render);
VideoPacketInit(MyVideoStream);
CodecInit();
if (!MyVideoStream->Decoder) {
MyVideoStream->CodecID = AV_CODEC_ID_NONE;
}

if ((MyVideoStream->Render = VideoNewRender(MyVideoStream))) {
VideoInit(MyVideoStream->Render);
MyVideoStream->Decoder = CodecVideoNewDecoder(MyVideoStream->Render);
VideoPacketInit(MyVideoStream);
}
}

return 0;
Expand Down
56 changes: 41 additions & 15 deletions softhddevice-drm.cpp
Expand Up @@ -94,6 +94,9 @@ void cSoftOsd::SetActive(bool on)
cSoftOsd::cSoftOsd(int left, int top, uint level)
:cOsd(left, top, level)
{
#ifdef DEBUG
fprintf(stderr, "[softhddev]%s:\n", __FUNCTION__);
#endif
#ifdef OSD_DEBUG
/* FIXME: OsdWidth/OsdHeight not correct!
*/
Expand All @@ -111,6 +114,9 @@ cSoftOsd::cSoftOsd(int left, int top, uint level)
*/
cSoftOsd::~cSoftOsd(void)
{
#ifdef DEBUG
fprintf(stderr, "[softhddev]%s:\n", __FUNCTION__);
#endif
#ifdef OSD_DEBUG
dsyslog("[softhddev] OSD %s: level %d\n", __FUNCTION__, OsdLevel);
#endif
Expand Down Expand Up @@ -363,6 +369,9 @@ void cSoftOsd::Flush(void)
*/
cOsd *cSoftOsdProvider::CreateOsd(int left, int top, uint level)
{
#ifdef DEBUG
fprintf(stderr, "[softhddev]%s:\n", __FUNCTION__);
#endif
#ifdef OSD_DEBUG
dsyslog("[softhddev] OSD %s: %d, %d, %d\n", __FUNCTION__, left, top, level);
#endif
Expand All @@ -386,6 +395,9 @@ bool cSoftOsdProvider::ProvidesTrueColor(void)
cSoftOsdProvider::cSoftOsdProvider(void)
: cOsdProvider()
{
#ifdef DEBUG
fprintf(stderr, "[softhddev]%s:\n", __FUNCTION__);
#endif
#ifdef OSD_DEBUG
dsyslog("[softhddev] OSD %s:\n", __FUNCTION__);
#endif
Expand Down Expand Up @@ -725,11 +737,16 @@ void cSoftHdDevice::MakePrimaryDevice(bool on)
#ifdef DEBUG
fprintf(stderr, "[softhddev]%s: %d\n", __FUNCTION__, on);
#endif
if (!on) {
::SoftHdDeviceExit();
} else {
::Start();
}

cDevice::MakePrimaryDevice(on);
if (on) {
new cSoftOsdProvider();
}
cDevice::MakePrimaryDevice(on);
if (on) {
new cSoftOsdProvider();
}
}


Expand Down Expand Up @@ -1147,6 +1164,9 @@ bool cPluginSoftHdDevice::ProcessArgs(int argc, char *argv[])
bool cPluginSoftHdDevice::Initialize(void)
{
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
#ifdef DEBUG
fprintf(stderr, "[softhddev]%s:\n", __FUNCTION__);
#endif

MyDevice = new cSoftHdDevice();

Expand All @@ -1158,19 +1178,22 @@ bool cPluginSoftHdDevice::Initialize(void)
*/
bool cPluginSoftHdDevice::Start(void)
{
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
#ifdef DEBUG
fprintf(stderr, "[softhddev]%s:\n", __FUNCTION__);
#endif

if (!MyDevice->IsPrimaryDevice()) {
isyslog("[softhddev] softhddevice %d is not the primary device!",
MyDevice->DeviceNumber());
if (ConfigMakePrimary) {
// Must be done in the main thread
dsyslog("[softhddev] makeing softhddevice %d the primary device!",
MyDevice->DeviceNumber());
DoMakePrimary = MyDevice->DeviceNumber() + 1;
if (!MyDevice->IsPrimaryDevice()) {
isyslog("[softhddev] softhddevice %d is not the primary device!",
MyDevice->DeviceNumber());
if (ConfigMakePrimary) {
// Must be done in the main thread
dsyslog("[softhddev] makeing softhddevice %d the primary device!",
MyDevice->DeviceNumber());
DoMakePrimary = MyDevice->DeviceNumber() + 1;
}
}
}
::Start();
::Start();

return true;
}
Expand All @@ -1182,6 +1205,9 @@ bool cPluginSoftHdDevice::Start(void)
void cPluginSoftHdDevice::Stop(void)
{
//dsyslog("[softhddev]%s:\n", __FUNCTION__);
#ifdef DEBUG
fprintf(stderr, "[softhddev]%s:\n", __FUNCTION__);
#endif

::Stop();
}
Expand Down
2 changes: 2 additions & 0 deletions softhddevice-drm.h
Expand Up @@ -166,6 +166,8 @@ class cSoftHdDevice:public cDevice
cSoftHdDevice(void);
virtual ~ cSoftHdDevice(void);

virtual cString DeviceName(void) const { return "softhddevice-drm"; }

virtual bool HasDecoder(void) const;
virtual bool CanReplay(void) const;
virtual bool SetPlayMode(ePlayMode);
Expand Down
16 changes: 12 additions & 4 deletions video_drm.c
Expand Up @@ -322,14 +322,13 @@ void ReadHWPlatform(VideoRender * render)
size_t read_size;

txt_buf = (char *) calloc(bufsize, sizeof(char));
if (!txt_buf)
printf("ReadHWPlatform: No memory!\n");

render->CodecMode = 0;

read_size = ReadLineFromFile(txt_buf, bufsize, "/sys/firmware/devicetree/base/compatible");
if (!read_size)
if (!read_size) {
free((void *)txt_buf);
return;
}

read_ptr = txt_buf;

Expand Down Expand Up @@ -671,6 +670,11 @@ static int SetupFB(VideoRender * render, struct drm_buf *buf,
}
buf->plane[1] = buf->plane[0] + buf->offset[1];
buf->plane[2] = buf->plane[0] + buf->offset[2];
#ifdef DRM_DEBUG
if (!render->buffers)
fprintf(stderr, "SetupFB: fb_id %d width %d height %d pix_fmt %4.4s\n",
buf->fb_id, buf->width, buf->height, (char *)&buf->pix_fmt);
#endif

return 0;
}
Expand Down Expand Up @@ -1536,6 +1540,10 @@ void VideoRenderFrame(VideoRender * render,
///
int64_t VideoGetClock(const VideoRender * render)
{
#ifdef DEBUG
fprintf(stderr, "VideoGetClock: %s\n",
Timestamp2String(render->pts * 1000 * av_q2d(*render->timebase)));
#endif
return render->pts;
}

Expand Down

0 comments on commit 4befc12

Please sign in to comment.