diff --git a/libmipsbox/audio.cpp b/libmipsbox/audio.cpp deleted file mode 100644 index f5de734..0000000 --- a/libmipsbox/audio.cpp +++ /dev/null @@ -1,418 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include "audio_lib.h" -#include "hal_debug.h" -#include - -#define AUDIO_DEVICE "/dev/dvb/adapter0/audio0" -#define hal_debug(args...) _hal_debug(HAL_DEBUG_AUDIO, this, args) -#define hal_info(args...) _hal_info(HAL_DEBUG_AUDIO, this, args) - -#include - -cAudio * audioDecoder = NULL; - -cAudio::cAudio(void *, void *, void *) -{ - fd = -1; - clipfd = -1; - mixer_fd = -1; - openDevice(); - Muted = false; -} - -cAudio::~cAudio(void) -{ - closeDevice(); -} - -void cAudio::openDevice(void) -{ - if (fd < 0) - { - if ((fd = open(AUDIO_DEVICE, O_RDWR)) < 0) - hal_info("openDevice: open failed (%m)\n"); - fcntl(fd, F_SETFD, FD_CLOEXEC); - //do_mute(true, false); - } - else - hal_info("openDevice: already open (fd = %d)\n", fd); -} - -void cAudio::closeDevice(void) -{ - if (fd > -1) { - close(fd); - fd = -1; - } - if (clipfd > -1) { - close(clipfd); - clipfd = -1; - } - if (mixer_fd > -1) { - close(mixer_fd); - mixer_fd = -1; - } -} - -int cAudio::do_mute(bool enable, bool remember) -{ - hal_debug("%s(%d, %d)\n", __FUNCTION__, enable, remember); - - char str[4]; - - if (remember) - Muted = enable; - - sprintf(str, "%d", Muted); - proc_put("/proc/stb/audio/j1_mute", str, strlen(str)); - - if (fd > 0) - { - if (ioctl(fd, AUDIO_SET_MUTE, enable) < 0) - perror("AUDIO_SET_MUTE"); - } - - return 0; -} - -int map_volume(const int volume) -{ - unsigned char vol = volume; - if (vol > 100) - vol = 100; - - // convert to -1dB steps - vol = 63 - vol * 63 / 100; - // now range is 63..0, where 0 is loudest - -#if BOXMODEL_VUPLUS_ALL - if (vol == 63) - vol = 255; -#endif - - return vol; -} - -int cAudio::setVolume(unsigned int left, unsigned int right) -{ - hal_info("cAudio::%s(%d, %d)\n", __func__, left, right); - - volume = (left + right) / 2; - int v = map_volume(volume); - - left = map_volume(volume); - right = map_volume(volume); - - audio_mixer_t mixer; - - mixer.volume_left = left; - mixer.volume_right = right; - - if (fd > 0) - { - if (ioctl(fd, AUDIO_SET_MIXER, &mixer) < 0) - perror("AUDIO_SET_MIXER"); - } - - char str[4]; - sprintf(str, "%d", v); - - proc_put("/proc/stb/avs/0/volume", str, strlen(str)); - - return 0; -} - -int cAudio::Start(void) -{ - int ret; - ret = ioctl(fd, AUDIO_PLAY); - return ret; -} - -int cAudio::Stop(void) -{ - return ioctl(fd, AUDIO_STOP); -} - -bool cAudio::Pause(bool Pcm) -{ - ioctl(fd, Pcm ? AUDIO_PAUSE : AUDIO_CONTINUE, 1); - return true; -} - -void cAudio::SetSyncMode(AVSYNC_TYPE Mode) -{ - hal_debug("%s %d\n", __func__, Mode); - ioctl(fd, AUDIO_SET_AV_SYNC, Mode); -} - -void cAudio::SetStreamType(int bypass) -{ - StreamType = bypass; - - hal_info("%s %d (0x%x)\n", __FUNCTION__, bypass, bypass); - - if (ioctl(fd, AUDIO_SET_BYPASS_MODE, bypass) < 0) - hal_info("%s: AUDIO_SET_BYPASS_MODE failed (%m)\n", __func__); -} - -int cAudio::setChannel(int channel) -{ - hal_debug("%s %d\n", __FUNCTION__, channel); - return 0; -} - -int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) -{ - int fmt; - unsigned int devmask, stereo, usable; - const char *dsp_dev = getenv("DSP_DEVICE"); - const char *mix_dev = getenv("MIX_DEVICE"); - hal_info("cAudio::%s ch %d srate %d bits %d le %d\n", __FUNCTION__, ch, srate, bits, little_endian); - if (clipfd > -1) { - hal_info("%s: clipfd already opened (%d)\n", __func__, clipfd); - return -1; - } - mixer_num = -1; - mixer_fd = -1; - /* a different DSP device can be given with DSP_DEVICE and MIX_DEVICE - * if this device cannot be opened, we fall back to the internal OSS device - * Example: - * modprobe snd-usb-audio - * export DSP_DEVICE=/dev/sound/dsp2 - * export MIX_DEVICE=/dev/sound/mixer2 - * neutrino - */ - if ((!dsp_dev) || (access(dsp_dev, W_OK))) { - if (dsp_dev) - hal_info("%s: DSP_DEVICE is set (%s) but cannot be opened," - " fall back to /dev/dsp\n", __func__, dsp_dev); - dsp_dev = "/dev/dsp"; - } - if ((!mix_dev) || (access(mix_dev, W_OK))) { - if (mix_dev) - hal_info("%s: MIX_DEVICE is set (%s) but cannot be opened," - " fall back to /dev/mixer\n", __func__, dsp_dev); - mix_dev = "/dev/mixer"; - } - hal_info("cAudio::%s: dsp_dev %s mix_dev %s\n", __func__, dsp_dev, mix_dev); /* NULL mix_dev is ok */ - /* the tdoss dsp driver seems to work only on the second open(). really. */ - clipfd = open(dsp_dev, O_WRONLY); - if (clipfd < 0) { - hal_info("%s open %s: %m\n", dsp_dev, __FUNCTION__); - return -1; - } - fcntl(clipfd, F_SETFD, FD_CLOEXEC); - /* no idea if we ever get little_endian == 0 */ - if (little_endian) - fmt = AFMT_S16_BE; - else - fmt = AFMT_S16_LE; - if (ioctl(clipfd, SNDCTL_DSP_SETFMT, &fmt)) - perror("SNDCTL_DSP_SETFMT"); - if (ioctl(clipfd, SNDCTL_DSP_CHANNELS, &ch)) - perror("SNDCTL_DSP_CHANNELS"); - if (ioctl(clipfd, SNDCTL_DSP_SPEED, &srate)) - perror("SNDCTL_DSP_SPEED"); -#if !BOXMODEL_BRE2ZE4K && !BOXMODEL_HD51 && !BOXMODEL_H7 - if (ioctl(clipfd, SNDCTL_DSP_RESET)) - perror("SNDCTL_DSP_RESET"); -#endif - - if (!mix_dev) - return 0; - - mixer_fd = open(mix_dev, O_RDWR); - if (mixer_fd < 0) { - hal_info("%s: open mixer %s failed (%m)\n", __func__, mix_dev); - /* not a real error */ - return 0; - } - if (ioctl(mixer_fd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) { - hal_info("%s: SOUND_MIXER_READ_DEVMASK %m\n", __func__); - devmask = 0; - } - if (ioctl(mixer_fd, SOUND_MIXER_READ_STEREODEVS, &stereo) == -1) { - hal_info("%s: SOUND_MIXER_READ_STEREODEVS %m\n", __func__); - stereo = 0; - } - usable = devmask & stereo; - if (usable == 0) { - hal_info("%s: devmask: %08x stereo: %08x, no usable dev :-(\n", - __func__, devmask, stereo); - close(mixer_fd); - mixer_fd = -1; - return 0; /* TODO: should we treat this as error? */ - } - /* __builtin_popcount needs GCC, it counts the set bits... */ - if (__builtin_popcount (usable) != 1) { - /* TODO: this code is not yet tested as I have only single-mixer devices... */ - hal_info("%s: more than one mixer control: devmask %08x stereo %08x\n" - "%s: querying MIX_NUMBER environment variable...\n", - __func__, devmask, stereo, __func__); - const char *tmp = getenv("MIX_NUMBER"); - if (tmp) - mixer_num = atoi(tmp); - hal_info("%s: mixer_num is %d -> device %08x\n", - __func__, mixer_num, (mixer_num >= 0) ? (1 << mixer_num) : 0); - /* no error checking, you'd better know what you are doing... */ - } else { - mixer_num = 0; - while (!(usable & 0x01)) { - mixer_num++; - usable >>= 1; - } - } - setVolume(volume, volume); - - return 0; -} - -int cAudio::WriteClip(unsigned char *buffer, int size) -{ - int ret, __attribute__ ((unused)) count = 1; - // hal_debug("cAudio::%s\n", __FUNCTION__); - if (clipfd < 0) { - hal_info("%s: clipfd not yet opened\n", __FUNCTION__); - return -1; - } -#if BOXMODEL_BRE2ZE4K || BOXMODEL_HD51 || BOXMODEL_H7 -again: -#endif - ret = write(clipfd, buffer, size); - if (ret < 0) { - hal_info("%s: write error (%m)\n", __FUNCTION__); - return ret; - } -#if BOXMODEL_BRE2ZE4K || BOXMODEL_HD51 || BOXMODEL_H7 - if (ret != size) { - hal_info("cAudio::%s: difference > to write (%d) != written (%d) try (%d) > reset dsp and restart write\n", __FUNCTION__, size, ret, count); - if (ioctl(clipfd, SNDCTL_DSP_RESET)) - perror("SNDCTL_DSP_RESET"); - count++; - if (count < 3) - goto again; - } -#endif - return ret; -}; - -int cAudio::StopClip() -{ - hal_info("cAudio::%s\n", __FUNCTION__); - - if (clipfd < 0) { - hal_info("%s: clipfd not yet opened\n", __FUNCTION__); - return -1; - } -#if BOXMODEL_VUPLUS_ARM - ioctl(clipfd, SNDCTL_DSP_RESET); -#endif - close(clipfd); - clipfd = -1; - if (mixer_fd > -1) { - close(mixer_fd); - mixer_fd = -1; - } - setVolume(volume, volume); - return 0; -}; - -void cAudio::getAudioInfo(int &type, int &layer, int &freq, int &bitrate, int &mode) -{ - hal_debug("%s\n", __FUNCTION__); - type = 0; - layer = 0; - freq = 0; - bitrate = 0; - mode = 0; -#if 0 - unsigned int atype; - static const int freq_mpg[] = {44100, 48000, 32000, 0}; - static const int freq_ac3[] = {48000, 44100, 32000, 0}; - scratchl2 i; - if (ioctl(fd, MPEG_AUD_GET_DECTYP, &atype) < 0) - perror("cAudio::getAudioInfo MPEG_AUD_GET_DECTYP"); - if (ioctl(fd, MPEG_AUD_GET_STATUS, &i) < 0) - perror("cAudio::getAudioInfo MPEG_AUD_GET_STATUS"); - - type = atype; -#if 0 -/* this does not work, some of the values are negative?? */ - AMPEGStatus A; - memcpy(&A, &i.word00, sizeof(i.word00)); - layer = A.audio_mpeg_layer; - mode = A.audio_mpeg_mode; - bitrate = A.audio_mpeg_bitrate; - switch(A.audio_mpeg_frequency) -#endif - /* layer and bitrate are not used anyway... */ - layer = 0; //(i.word00 >> 17) & 3; - bitrate = 0; //(i.word00 >> 12) & 3; - switch (type) - { - case 0: /* MPEG */ - mode = (i.word00 >> 6) & 3; - freq = freq_mpg[(i.word00 >> 10) & 3]; - break; - case 1: /* AC3 */ - mode = (i.word00 >> 28) & 7; - freq = freq_ac3[(i.word00 >> 16) & 3]; - break; - default: - mode = 0; - freq = 0; - } - //fprintf(stderr, "type: %d layer: %d freq: %d bitrate: %d mode: %d\n", type, layer, freq, bitrate, mode); -#endif -}; - -void cAudio::SetSRS(int /*iq_enable*/, int /*nmgr_enable*/, int /*iq_mode*/, int /*iq_level*/) -{ - hal_debug("%s\n", __FUNCTION__); -}; - -void cAudio::SetHdmiDD(bool enable) -{ - const char *opt[] = { "downmix", "passthrough" }; - hal_debug("%s %d\n", __func__, enable); - proc_put("/proc/stb/audio/ac3", opt[enable], strlen(opt[enable])); -} - -void cAudio::SetSpdifDD(bool enable) -{ - //using this function for dts passthrough - const char *opt[] = { "downmix", "passthrough" }; - hal_debug("%s %d\n", __func__, enable); - proc_put("/proc/stb/audio/dts", opt[enable], strlen(opt[enable])); -} - -void cAudio::ScheduleMute(bool On) -{ - hal_debug("%s %d\n", __FUNCTION__, On); -} - -void cAudio::EnableAnalogOut(bool enable) -{ - hal_debug("%s %d\n", __FUNCTION__, enable); -} - -#define AUDIO_BYPASS_ON 0 -#define AUDIO_BYPASS_OFF 1 -void cAudio::setBypassMode(bool disable) -{ - int mode = disable ? AUDIO_BYPASS_OFF : AUDIO_BYPASS_ON; - if (ioctl(fd, AUDIO_SET_BYPASS_MODE, mode) < 0) - hal_info("%s AUDIO_SET_BYPASS_MODE %d: %m\n", __func__, mode); -} diff --git a/libmipsbox/audio.cpp b/libmipsbox/audio.cpp new file mode 120000 index 0000000..a5bac70 --- /dev/null +++ b/libmipsbox/audio.cpp @@ -0,0 +1 @@ +../libarmbox/audio.cpp \ No newline at end of file diff --git a/libmipsbox/audio_lib.h b/libmipsbox/audio_lib.h deleted file mode 100644 index 2eee1fa..0000000 --- a/libmipsbox/audio_lib.h +++ /dev/null @@ -1,83 +0,0 @@ -/* public header file */ - -#ifndef __AUDIO_LIB_H__ -#define __AUDIO_LIB_H__ - -#include "cs_types.h" - -typedef enum -{ - AUDIO_SYNC_WITH_PTS, - AUDIO_NO_SYNC, - AUDIO_SYNC_AUDIO_MASTER -} AUDIO_SYNC_MODE; - -typedef enum { - HDMI_ENCODED_OFF, - HDMI_ENCODED_AUTO, - HDMI_ENCODED_FORCED -} HDMI_ENCODED_MODE; - -class mixerVolume; - -class cAudio -{ - friend class cPlayback; - private: - int fd; - bool Muted; - - int clipfd; /* for pcm playback */ - int mixer_fd; /* if we are using the OSS mixer */ - int mixer_num; /* oss mixer to use, if any */ - - int StreamType; - AUDIO_SYNC_MODE SyncMode; - bool started; - - int volume; - - int do_mute(bool enable, bool remember); - void setBypassMode(bool disable); - - public: - /* construct & destruct */ - cAudio(void *, void *, void *); - ~cAudio(void); - - void openDevice(void); - void closeDevice(void); - - void *GetHandle() { return NULL; }; - /* shut up */ - int mute(bool remember = true) { return do_mute(true, remember); }; - int unmute(bool remember = true) { return do_mute(false, remember); }; - - /* volume, min = 0, max = 255 */ - int setVolume(unsigned int left, unsigned int right); - int getVolume(void) { return volume;} - bool getMuteStatus(void) { return Muted; }; - - /* start and stop audio */ - int Start(void); - int Stop(void); - bool Pause(bool Pcm = true); - void SetStreamType(int bypass); - int GetStreamType(void) { return StreamType; } - void SetSyncMode(AVSYNC_TYPE Mode); - - /* select channels */ - int setChannel(int channel); - int PrepareClipPlay(int uNoOfChannels, int uSampleRate, int uBitsPerSample, int bLittleEndian); - int WriteClip(unsigned char * buffer, int size); - int StopClip(); - void getAudioInfo(int &type, int &layer, int& freq, int &bitrate, int &mode); - void SetSRS(int iq_enable, int nmgr_enable, int iq_mode, int iq_level); - bool IsHdmiDDSupported() { return true; }; - void SetHdmiDD(bool enable); - void SetSpdifDD(bool enable); - void ScheduleMute(bool On); - void EnableAnalogOut(bool enable); -}; - -#endif // __AUDIO_LIB_H__ diff --git a/libmipsbox/audio_lib.h b/libmipsbox/audio_lib.h new file mode 120000 index 0000000..f12d7d5 --- /dev/null +++ b/libmipsbox/audio_lib.h @@ -0,0 +1 @@ +../libarmbox/audio_lib.h \ No newline at end of file diff --git a/libmipsbox/dmx.cpp b/libmipsbox/dmx.cpp deleted file mode 100644 index ddb93fe..0000000 --- a/libmipsbox/dmx.cpp +++ /dev/null @@ -1,623 +0,0 @@ -/* - * cDemux implementation for arm receivers (tested on mutant hd51 - * hardware) - * - * derived from libtriple/dmx_td.cpp - * - * (C) 2010-2013 Stefan Seyfried - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include "dmx_hal.h" -#include "hal_debug.h" - -#include "video_lib.h" -/* needed for getSTC... */ -extern cVideo *videoDecoder; - -#define hal_debug(args...) _hal_debug(HAL_DEBUG_DEMUX, this, args) -#define hal_info(args...) _hal_info(HAL_DEBUG_DEMUX, this, args) -#define hal_debug_c(args...) _hal_debug(HAL_DEBUG_DEMUX, NULL, args) -#define hal_info_c(args...) _hal_info(HAL_DEBUG_DEMUX, NULL, args) -#define hal_info_z(args...) _hal_info(HAL_DEBUG_DEMUX, thiz, args) -#define hal_debug_z(args...) _hal_debug(HAL_DEBUG_DEMUX, thiz, args) - -#define dmx_err(_errfmt, _errstr, _revents) do { \ - hal_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ -} while(0); - -cDemux *videoDemux = NULL; -cDemux *audioDemux = NULL; -//cDemux *pcrDemux = NULL; - -static const char *DMX_T[] = { - "DMX_INVALID", - "DMX_VIDEO", - "DMX_AUDIO", - "DMX_PES", - "DMX_PSI", - "DMX_PIP", - "DMX_TP", - "DMX_PCR" -}; - -/* this is the number of different cDemux() units, not the number of - * /dev/dvb/.../demuxX devices! */ -#if BOXMODEL_VUULTIMO4K -#define NUM_DEMUX 24 -#else -#if BOXMODEL_VUSOLO4K || BOXMODEL_VUDUO4K || BOXMODEL_VUDUO4KSE || BOXMODEL_VUUNO4KSE || BOXMODEL_VUUNO4K -#define NUM_DEMUX 16 -#else -#define NUM_DEMUX 4 -#endif -#endif -/* the current source of each cDemux unit */ -#if BOXMODEL_VUULTIMO4K -static int dmx_source[NUM_DEMUX] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -#else -#if BOXMODEL_VUSOLO4K || BOXMODEL_VUDUO4K || BOXMODEL_VUDUO4KSE || BOXMODEL_VUUNO4KSE || BOXMODEL_VUUNO4K -static int dmx_source[NUM_DEMUX] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -#else -static int dmx_source[NUM_DEMUX] = { 0, 0, 0, 0 }; -#endif -#endif - -char dmxdev[32]; -static char* devname(int adapter, int demux) { - snprintf(dmxdev, sizeof(dmxdev), "/dev/dvb/adapter%d/demux%d", adapter, demux); - return dmxdev; -} - -/* map the device numbers. */ -#if BOXMODEL_VUULTIMO4K -#define NUM_DEMUXDEV 24 -#else -#if BOXMODEL_VUSOLO4K || BOXMODEL_VUDUO4K || BOXMODEL_VUDUO4KSE || BOXMODEL_VUUNO4KSE || BOXMODEL_VUUNO4K -#define NUM_DEMUXDEV 16 -#else -#define NUM_DEMUXDEV 8 -#endif -#endif - -/* did we already DMX_SET_SOURCE on that demux device? */ -#if BOXMODEL_VUULTIMO4K -static bool init[NUM_DEMUXDEV] = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }; -#else -#if BOXMODEL_VUSOLO4K || BOXMODEL_VUDUO4K || BOXMODEL_VUDUO4KSE || BOXMODEL_VUUNO4KSE || BOXMODEL_VUUNO4K -static bool init[NUM_DEMUXDEV] = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }; -#else -static bool init[NUM_DEMUXDEV] = { false, false, false, false, false, false, false, false }; -#endif -#endif - -typedef struct dmx_pdata { - int last_source; - OpenThreads::Mutex *mutex; -} dmx_pdata; -#define P ((dmx_pdata *)pdata) - -cDemux::cDemux(int n) -{ - if (n < 0 || n >= NUM_DEMUX) - { - hal_info("%s ERROR: n invalid (%d)\n", __FUNCTION__, n); - num = 0; - } - else - num = n; - fd = -1; - pdata = (void *)calloc(1, sizeof(dmx_pdata)); - P->last_source = -1; - P->mutex = new OpenThreads::Mutex; - dmx_type = DMX_INVALID; -} - -cDemux::~cDemux() -{ - hal_debug("%s #%d fd: %d\n", __FUNCTION__, num, fd); - Close(); - /* wait until Read() has released the mutex */ - (*P->mutex).lock(); - (*P->mutex).unlock(); - free(P->mutex); - free(pdata); - pdata = NULL; -} - -bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBufferSize) -{ - if (fd > -1) - hal_info("%s FD ALREADY OPENED? fd = %d\n", __FUNCTION__, fd); - - dmx_type = pes_type; - buffersize = uBufferSize; - - /* return code is unchecked anyway... */ - return true; -} - -static bool _open(cDemux *thiz, int num, int &fd, int &last_source, DMX_CHANNEL_TYPE dmx_type, int buffersize) -{ - int flags = O_RDWR|O_CLOEXEC; - int devnum = dmx_source[num]; - if (last_source == devnum) { - hal_debug_z("%s #%d: source (%d) did not change\n", __func__, num, last_source); - if (fd > -1) - return true; - } - if (fd > -1) { - /* we changed source -> close and reopen the fd */ - hal_debug_z("%s #%d: FD ALREADY OPENED fd = %d lastsource %d devnum %d\n", - __func__, num, fd, last_source, devnum); - close(fd); - } - - if (dmx_type != DMX_PSI_CHANNEL) - flags |= O_NONBLOCK; - - fd = open(devname(0, devnum), flags); - if (fd < 0) - { - hal_info_z("%s %s: %m\n", __FUNCTION__, devname(0, devnum)); - return false; - } - hal_debug_z("%s #%d pes_type: %s(%d), uBufferSize: %d fd: %d\n", __func__, - num, DMX_T[dmx_type], dmx_type, buffersize, fd); - - /* this would actually need locking, but the worst that weill happen is, that - * we'll DMX_SET_SOURCE twice per device, so don't bother... */ - if (!init[devnum]) - { - /* this should not change anything... */ - int n = DMX_SOURCE_FRONT0 + devnum; - hal_info_z("%s: setting %s to source %d\n", __func__, devname(0, devnum), n); - if (ioctl(fd, DMX_SET_SOURCE, &n) < 0) - hal_info_z("%s DMX_SET_SOURCE failed!\n", __func__); - else - init[devnum] = true; - } - if (buffersize == 0) - buffersize = 0xffff; // may or may not be reasonable --martii - if (buffersize > 0) - { - /* probably uBufferSize == 0 means "use default size". TODO: find a reasonable default */ - if (ioctl(fd, DMX_SET_BUFFER_SIZE, buffersize) < 0) - hal_info_z("%s DMX_SET_BUFFER_SIZE failed (%m)\n", __func__); - } - - last_source = devnum; - return true; -} - -void cDemux::Close(void) -{ - hal_debug("%s #%d, fd = %d\n", __FUNCTION__, num, fd); - if (fd < 0) - { - hal_info("%s #%d: not open!\n", __FUNCTION__, num); - return; - } - - pesfds.clear(); - ioctl(fd, DMX_STOP); - close(fd); - fd = -1; -} - -bool cDemux::Start(bool) -{ - hal_debug("%s #%d fd: %d type: %s\n", __func__, num, fd, DMX_T[dmx_type]); - if (fd < 0) - { - hal_info("%s #%d: not open!\n", __FUNCTION__, num); - return false; - } - ioctl(fd, DMX_START); - return true; -} - -bool cDemux::Stop(void) -{ - hal_debug("%s #%d fd: %d type: %s\n", __func__, num, fd, DMX_T[dmx_type]); - if (fd < 0) - { - hal_info("%s #%d: not open!\n", __FUNCTION__, num); - return false; - } - ioctl(fd, DMX_STOP); - return true; -} - -int cDemux::Read(unsigned char *buff, int len, int timeout) -{ -#if 0 - if (len != 4095 && timeout != 10) - fprintf(stderr, "cDemux::%s #%d fd: %d type: %s len: %d timeout: %d\n", - __FUNCTION__, num, fd, DMX_T[dmx_type], len, timeout); -#endif - if (fd < 0) - { - hal_info("%s #%d: not open!\n", __func__, num); - return -1; - } - /* avoid race in destructor: ~cDemux needs to wait until Read() returns */ - OpenThreads::ScopedLock m_lock(*P->mutex); - int rc; - int to = timeout; - struct pollfd ufds; - ufds.fd = fd; - ufds.events = POLLIN|POLLPRI|POLLERR; - ufds.revents = 0; - - /* hack: if the frontend loses and regains lock, the demuxer often will not - * return from read(), so as a "emergency exit" for e.g. NIT scan, set a (long) - * timeout here */ - if (dmx_type == DMX_PSI_CHANNEL && timeout <= 0) - to = 60 * 1000; - - if (to > 0) - { - retry: - rc = ::poll(&ufds, 1, to); - if (ufds.fd != fd) - { - /* Close() will set fd to -1, this is normal. Everything else is not. */ - hal_info("%s:1 ========== fd has changed, %d->%d ==========\n", __func__, ufds.fd, fd); - return -1; - } - if (!rc) - { - if (timeout == 0) /* we took the emergency exit */ - { - dmx_err("timed out for timeout=0!, %s", "", 0); - return -1; /* this timeout is an error */ - } - return 0; // timeout - } - else if (rc < 0) - { - dmx_err("poll: %s,", strerror(errno), 0) - //hal_info("%s poll: %m\n", __FUNCTION__); - /* happens, when running under gdb... */ - if (errno == EINTR) - goto retry; - return -1; - } -#if 0 - if (ufds.revents & POLLERR) /* POLLERR means buffer error, i.e. buffer overflow */ - { - dmx_err("received %s,", "POLLERR", ufds.revents); - /* this seems to happen sometimes at recording start, without bad effects */ - return 0; - } -#endif - if (ufds.revents & POLLHUP) /* we get POLLHUP if e.g. a too big DMX_BUFFER_SIZE was set */ - { - dmx_err("received %s,", "POLLHUP", ufds.revents); - return -1; - } - if (!(ufds.revents & POLLIN)) /* we requested POLLIN but did not get it? */ - { - dmx_err("received %s, please report!", "POLLIN", ufds.revents); - return 0; - } - } - if (ufds.fd != fd) /* does this ever happen? and if, is it harmful? */ - { /* read(-1,...) will just return EBADF anyway... */ - hal_info("%s:2 ========== fd has changed, %d->%d ==========\n", __func__, ufds.fd, fd); - return -1; - } - - rc = ::read(fd, buff, len); - //fprintf(stderr, "fd %d ret: %d\n", fd, rc); - if (rc < 0) - dmx_err("read: %s", strerror(errno), 0); - - return rc; -} - -bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, - const unsigned char * const mask, int len, int timeout, - const unsigned char * const negmask) -{ - struct dmx_sct_filter_params s_flt; - memset(&s_flt, 0, sizeof(s_flt)); - pid = _pid; - - _open(this, num, fd, P->last_source, dmx_type, buffersize); - - if (len > DMX_FILTER_SIZE) - { - hal_info("%s #%d: len too long: %d, DMX_FILTER_SIZE %d\n", __func__, num, len, DMX_FILTER_SIZE); - len = DMX_FILTER_SIZE; - } - flt = filter[0]; - s_flt.pid = pid; - s_flt.timeout = timeout; - memcpy(s_flt.filter.filter, filter, len); - memcpy(s_flt.filter.mask, mask, len); - if (negmask != NULL) - memcpy(s_flt.filter.mode, negmask, len); - - s_flt.flags = DMX_IMMEDIATE_START|DMX_CHECK_CRC; - - int to = 0; - switch (filter[0]) - { - case 0x00: /* program_association_section */ - to = 2000; - break; - case 0x01: /* conditional_access_section */ - to = 6000; - break; - case 0x02: /* program_map_section */ - to = 1500; - break; - case 0x03: /* transport_stream_description_section */ - to = 10000; - break; - /* 0x04 - 0x3F: reserved */ - case 0x40: /* network_information_section - actual_network */ - to = 10000; - break; - case 0x41: /* network_information_section - other_network */ - to = 15000; - break; - case 0x42: /* service_description_section - actual_transport_stream */ - to = 10000; - break; - /* 0x43 - 0x45: reserved for future use */ - case 0x46: /* service_description_section - other_transport_stream */ - to = 10000; - break; - /* 0x47 - 0x49: reserved for future use */ - case 0x4A: /* bouquet_association_section */ - to = 11000; - break; - /* 0x4B - 0x4D: reserved for future use */ - case 0x4E: /* event_information_section - actual_transport_stream, present/following */ - to = 2000; - break; - case 0x4F: /* event_information_section - other_transport_stream, present/following */ - to = 10000; - break; - /* 0x50 - 0x5F: event_information_section - actual_transport_stream, schedule */ - /* 0x60 - 0x6F: event_information_section - other_transport_stream, schedule */ - case 0x70: /* time_date_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - s_flt.flags |= DMX_ONESHOT; - //s_flt.pid = 0x0014; - to = 30000; - break; - case 0x71: /* running_status_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - to = 0; - break; - case 0x72: /* stuffing_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - to = 0; - break; - case 0x73: /* time_offset_section */ - s_flt.flags |= DMX_ONESHOT; - //s_flt.pid = 0x0014; - to = 30000; - break; - /* 0x74 - 0x7D: reserved for future use */ - case 0x7E: /* discontinuity_information_section */ - s_flt.flags &= ~DMX_CHECK_CRC; /* section has no CRC */ - to = 0; - break; - case 0x7F: /* selection_information_section */ - to = 0; - break; - /* 0x80 - 0x8F: ca_message_section */ - /* 0x90 - 0xFE: user defined */ - /* 0xFF: reserved */ - default: - //return -1; - break; - } - /* the negmask == NULL is a hack: the users of negmask are PMT-update - * and sectionsd EIT-Version change. And they really want no timeout - * if timeout == 0 instead of "default timeout" */ - if (timeout == 0 && negmask == NULL) - s_flt.timeout = to; - - hal_debug("%s #%d pid:0x%04hx fd:%d type:%s len:%d to:%d flags:%x flt[0]:%02x\n", __func__, num, - pid, fd, DMX_T[dmx_type], len, s_flt.timeout, s_flt.flags, s_flt.filter.filter[0]); -#if 0 - fprintf(stderr,"filt: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.filter[i]); fprintf(stderr, "\n"); - fprintf(stderr,"mask: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mask [i]); fprintf(stderr, "\n"); - fprintf(stderr,"mode: "); for (int i = 0; i < len; i++) fprintf(stderr, "%02hhx ", s_flt.filter.mode [i]); fprintf(stderr, "\n"); -#endif - ioctl (fd, DMX_STOP); - if (ioctl(fd, DMX_SET_FILTER, &s_flt) < 0) - return false; - - return true; -} - -bool cDemux::pesFilter(const unsigned short _pid) -{ - struct dmx_pes_filter_params p_flt; - pid = _pid; - flt = 0; - /* allow PID 0 for web streaming e.g. - * this check originally is from tuxbox cvs but I'm not sure - * what it is good for... - if (pid <= 0x0001 && dmx_type != DMX_PCR_ONLY_CHANNEL) - return false; - */ - if ((pid >= 0x0002 && pid <= 0x000f) || pid >= 0x1fff) - return false; - - hal_debug("%s #%d pid: 0x%04hx fd: %d type: %s\n", __FUNCTION__, num, pid, fd, DMX_T[dmx_type]); - - _open(this, num, fd, P->last_source, dmx_type, buffersize); - - memset(&p_flt, 0, sizeof(p_flt)); - p_flt.pid = pid; - p_flt.output = DMX_OUT_DECODER; - p_flt.input = DMX_IN_FRONTEND; - p_flt.flags = 0; - - switch (dmx_type) - { - case DMX_PCR_ONLY_CHANNEL: - p_flt.pes_type = DMX_PES_PCR; - break; - case DMX_AUDIO_CHANNEL: - p_flt.pes_type = DMX_PES_AUDIO; - break; - case DMX_VIDEO_CHANNEL: - p_flt.pes_type = DMX_PES_VIDEO; - break; - case DMX_PIP_CHANNEL: /* PIP is a special version of DMX_VIDEO_CHANNEL */ - p_flt.pes_type = DMX_PES_VIDEO1; - break; - case DMX_PES_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TAP; - break; - case DMX_TP_CHANNEL: - p_flt.pes_type = DMX_PES_OTHER; - p_flt.output = DMX_OUT_TSDEMUX_TAP; - break; - default: - hal_info("%s #%d invalid dmx_type %d!\n", __func__, num, dmx_type); - return false; - } - return (ioctl(fd, DMX_SET_PES_FILTER, &p_flt) >= 0); -} - -void cDemux::SetSyncMode(AVSYNC_TYPE /*mode*/) -{ - hal_debug("%s #%d\n", __FUNCTION__, num); -} - -void *cDemux::getBuffer() -{ - hal_debug("%s #%d\n", __FUNCTION__, num); - return NULL; -} - -void *cDemux::getChannel() -{ - hal_debug("%s #%d\n", __FUNCTION__, num); - return NULL; -} - -bool cDemux::addPid(unsigned short Pid) -{ - hal_debug("%s: pid 0x%04hx\n", __func__, Pid); - pes_pids pfd; - int ret; - if (dmx_type != DMX_TP_CHANNEL) - { - hal_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid); - return false; - } - _open(this, num, fd, P->last_source, dmx_type, buffersize); - if (fd == -1) - hal_info("%s bucketfd not yet opened? pid=%hx\n", __FUNCTION__, Pid); - pfd.fd = fd; /* dummy */ - pfd.pid = Pid; - pesfds.push_back(pfd); - ret = (ioctl(fd, DMX_ADD_PID, &Pid)); - if (ret < 0) - hal_info("%s: DMX_ADD_PID (%m) pid=%hx\n", __func__, Pid); - return (ret != -1); -} - -void cDemux::removePid(unsigned short Pid) -{ - if (dmx_type != DMX_TP_CHANNEL) - { - hal_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid); - return; - } - for (std::vector::iterator i = pesfds.begin(); i != pesfds.end(); ++i) - { - if ((*i).pid == Pid) { - hal_debug("removePid: removing demux fd %d pid 0x%04x\n", fd, Pid); - if (ioctl(fd, DMX_REMOVE_PID, Pid) < 0) - hal_info("%s: (DMX_REMOVE_PID, 0x%04hx): %m\n", __func__, Pid); - pesfds.erase(i); - return; /* TODO: what if the same PID is there multiple times */ - } - } - hal_info("%s pid 0x%04x not found\n", __FUNCTION__, Pid); -} - -void cDemux::getSTC(int64_t * STC) -{ - /* apparently I can only get the PTS of the video decoder, - * but that's good enough for dvbsub */ - hal_debug("%s #%d\n", __func__, num); - int64_t pts = 0; - if (videoDecoder) - pts = videoDecoder->GetPTS(); - *STC = pts; -} - -int cDemux::getUnit(void) -{ - hal_debug("%s #%d\n", __FUNCTION__, num); - /* just guessed that this is the right thing to do. - right now this is only used by the CA code which is stubbed out - anyway */ - return num; -} - -bool cDemux::SetSource(int unit, int source) -{ - if (unit >= NUM_DEMUX || unit < 0) { - hal_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX); - return false; - } - hal_debug_c("%s(%d, %d) => %d to %d\n", __func__, unit, source, dmx_source[unit], source); - if (source < 0 || source >= NUM_DEMUXDEV) - hal_info_c("%s(%d, %d) ERROR: source %d out of range!\n", __func__, unit, source, source); - else - dmx_source[unit] = source; - return true; -} - -int cDemux::GetSource(int unit) -{ - if (unit >= NUM_DEMUX || unit < 0) { - hal_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX); - return -1; - } - hal_debug_c("%s(%d) => %d\n", __func__, unit, dmx_source[unit]); - return dmx_source[unit]; -} diff --git a/libmipsbox/dmx.cpp b/libmipsbox/dmx.cpp new file mode 120000 index 0000000..a8e7f08 --- /dev/null +++ b/libmipsbox/dmx.cpp @@ -0,0 +1 @@ +../libarmbox/dmx.cpp \ No newline at end of file diff --git a/libmipsbox/hdmi_cec.cpp b/libmipsbox/hdmi_cec.cpp deleted file mode 100644 index 8504372..0000000 --- a/libmipsbox/hdmi_cec.cpp +++ /dev/null @@ -1,852 +0,0 @@ -/* - Copyright (C) 2018-2021 TangoCash - - License: GPLv2 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include "linux-uapi-cec.h" -#include "hdmi_cec.h" -#include "hdmi_cec_types.h" -#include "hal_debug.h" - -#define RED "\x1B[31m" -#define GREEN "\x1B[32m" -#define NORMAL "\x1B[0m" - -#define EPOLL_WAIT_TIMEOUT (-1) -#define EPOLL_MAX_EVENTS (1) - -#define hal_debug(args...) _hal_debug(HAL_DEBUG_INIT, this, args) -#define hal_info(args...) _hal_info(HAL_DEBUG_INIT, this, args) -#define hal_debug_c(args...) _hal_debug(HAL_DEBUG_INIT, NULL, args) -#define hal_info_c(args...) _hal_info(HAL_DEBUG_INIT, NULL, args) - -#define fop(cmd, args...) ({ \ - int _r; \ - if (fd >= 0) { \ - if ((_r = ::cmd(fd, args)) < 0) \ - hal_info(#cmd"(fd, "#args")\n"); \ - else \ - hal_debug(#cmd"(fd, "#args")\n");\ - } \ - else { _r = fd; } \ - _r; \ -}) - -#define CEC_FALLBACK_DEVICE "/dev/cec0" -#define CEC_HDMIDEV "/dev/hdmi_cec" -#if BOXMODEL_H7 -#define RC_DEVICE "/dev/input/event2" -#else -#define RC_DEVICE "/dev/input/event1" -#endif - -hdmi_cec * hdmi_cec::hdmi_cec_instance = NULL; - -//hack to get an instance before first call -hdmi_cec * CEC = hdmi_cec::getInstance(); - -hdmi_cec::hdmi_cec() -{ - standby_cec_activ = autoview_cec_activ = standby = muted = false; - hdmiFd = -1; - volume = 0; - fallback = false; - tv_off = true; - deviceType = CEC_LOG_ADDR_TYPE_UNREGISTERED; - audio_destination = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM; -} - -hdmi_cec::~hdmi_cec() -{ - if (hdmiFd >= 0) - { - close(hdmiFd); - hdmiFd = -1; - } -} - -hdmi_cec* hdmi_cec::getInstance() -{ - if (hdmi_cec_instance == NULL) - { - hdmi_cec_instance = new hdmi_cec(); - hal_info_c(GREEN"[CEC] new instance created \n"NORMAL); - } - return hdmi_cec_instance; -} - -bool hdmi_cec::SetCECMode(VIDEO_HDMI_CEC_MODE _deviceType) -{ - physicalAddress[0] = 0x10; - physicalAddress[1] = 0x00; - logicalAddress = 1; - - if (_deviceType == VIDEO_HDMI_CEC_MODE_OFF) - { - Stop(); - hal_info(GREEN"[CEC] switch off %s\n"NORMAL, __func__); - return false; - } - else - deviceType = _deviceType; - - hal_info(GREEN"[CEC] switch on %s\n"NORMAL, __func__); - -#if BOXMODEL_VUPLUS_ALL - if (hdmiFd == -1) - { - hdmiFd = ::open(CEC_HDMIDEV, O_RDWR | O_NONBLOCK | O_CLOEXEC); - if (hdmiFd >= 0) - { - ::ioctl(hdmiFd, 0); /* flush old messages */ - } - } -#endif - - if (hdmiFd == -1) - { - hdmiFd = open(CEC_FALLBACK_DEVICE, O_RDWR | O_CLOEXEC); - - if (hdmiFd >= 0) - { - fallback = true; -#if BOXMODEL_VUPLUS_ALL - hal_info(RED"[CEC] fallback on %s\n"NORMAL, __func__); -#endif - - __u32 monitor = CEC_MODE_INITIATOR | CEC_MODE_FOLLOWER; - struct cec_caps caps = {}; - - if (ioctl(hdmiFd, CEC_ADAP_G_CAPS, &caps) < 0) - hal_info(RED"[CEC] %s: get caps failed (%m)\n"NORMAL, __func__); - - if (caps.capabilities & CEC_CAP_LOG_ADDRS) - { - struct cec_log_addrs laddrs = {}; - - if (ioctl(hdmiFd, CEC_ADAP_S_LOG_ADDRS, &laddrs) < 0) - hal_info(RED"[CEC] %s: reset log addr failed (%m)\n"NORMAL, __func__); - - memset(&laddrs, 0, sizeof(laddrs)); - - /* - * NOTE: cec_version, osd_name and deviceType should be made configurable, - * CEC_ADAP_S_LOG_ADDRS delayed till the desired values are available - * (saves us some startup speed as well, polling for a free logical address - * takes some time) - */ - laddrs.cec_version = CEC_OP_CEC_VERSION_2_0; - strcpy(laddrs.osd_name, "neutrino"); - laddrs.vendor_id = CEC_VENDOR_ID_NONE; - - switch (deviceType) - { - case CEC_LOG_ADDR_TV: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TV; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TV; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TV; - break; - case CEC_LOG_ADDR_RECORD_1: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_RECORD; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_RECORD; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_RECORD; - break; - case CEC_LOG_ADDR_TUNER_1: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TUNER; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TUNER; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TUNER; - break; - case CEC_LOG_ADDR_PLAYBACK_1: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_PLAYBACK; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_PLAYBACK; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_PLAYBACK; - break; - case CEC_LOG_ADDR_AUDIOSYSTEM: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_AUDIOSYSTEM; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM; - break; - default: - laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_UNREGISTERED; - laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_SWITCH; - laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_SWITCH; - break; - } - laddrs.num_log_addrs++; - - if (ioctl(hdmiFd, CEC_ADAP_S_LOG_ADDRS, &laddrs) < 0) - hal_info(RED"[CEC] %s: et log addr failed (%m)\n"NORMAL, __func__); - } - - if (ioctl(hdmiFd, CEC_S_MODE, &monitor) < 0) - hal_info(RED"[CEC] %s: monitor failed (%m)\n"NORMAL, __func__); - - } - } - - if (hdmiFd >= 0) - { - GetCECAddressInfo(); - - if(autoview_cec_activ) - SetCECState(false); - - Start(); - return true; - - } - return false; -} - -void hdmi_cec::GetCECAddressInfo() -{ - if (hdmiFd >= 0) - { - bool hasdata = false; - struct addressinfo addressinfo; - - if (fallback) - { - __u16 phys_addr; - struct cec_log_addrs laddrs = {}; - - ::ioctl(hdmiFd, CEC_ADAP_G_PHYS_ADDR, &phys_addr); - addressinfo.physical[0] = (phys_addr >> 8) & 0xff; - addressinfo.physical[1] = phys_addr & 0xff; - - ::ioctl(hdmiFd, CEC_ADAP_G_LOG_ADDRS, &laddrs); - addressinfo.logical = laddrs.log_addr[0]; - - switch (laddrs.log_addr_type[0]) - { - case CEC_LOG_ADDR_TYPE_TV: - addressinfo.type = CEC_LOG_ADDR_TV; - break; - case CEC_LOG_ADDR_TYPE_RECORD: - addressinfo.type = CEC_LOG_ADDR_RECORD_1; - break; - case CEC_LOG_ADDR_TYPE_TUNER: - addressinfo.type = CEC_LOG_ADDR_TUNER_1; - break; - case CEC_LOG_ADDR_TYPE_PLAYBACK: - addressinfo.type = CEC_LOG_ADDR_PLAYBACK_1; - break; - case CEC_LOG_ADDR_TYPE_AUDIOSYSTEM: - addressinfo.type = CEC_LOG_ADDR_AUDIOSYSTEM; - break; - case CEC_LOG_ADDR_TYPE_UNREGISTERED: - default: - addressinfo.type = CEC_LOG_ADDR_UNREGISTERED; - break; - } - hasdata = true; - } - else - { - if (::ioctl(hdmiFd, 1, &addressinfo) >= 0) - { - hasdata = true; - } - } - if (hasdata) - { - deviceType = addressinfo.type; - logicalAddress = addressinfo.logical; - if (memcmp(physicalAddress, addressinfo.physical, sizeof(physicalAddress))) - { - hal_info(GREEN"[CEC] %s: detected physical address change: %02X%02X --> %02X%02X\n"NORMAL, __func__, physicalAddress[0], physicalAddress[1], addressinfo.physical[0], addressinfo.physical[1]); - memcpy(physicalAddress, addressinfo.physical, sizeof(physicalAddress)); - ReportPhysicalAddress(); - } - } - } -} - -void hdmi_cec::ReportPhysicalAddress() -{ - struct cec_message txmessage; - txmessage.initiator = logicalAddress; - txmessage.destination = CEC_LOG_ADDR_BROADCAST; - txmessage.data[0] = CEC_MSG_REPORT_PHYSICAL_ADDR; - txmessage.data[1] = physicalAddress[0]; - txmessage.data[2] = physicalAddress[1]; - txmessage.data[3] = deviceType; - txmessage.length = 4; - SendCECMessage(txmessage); -} - -void hdmi_cec::SendCECMessage(struct cec_message &txmessage, int sleeptime) -{ - if (hdmiFd >= 0) - { - - char str[txmessage.length*6]; - for (int i = 0; i < txmessage.length; i++) - { - sprintf(str+(i*6),"[0x%02X]", txmessage.data[i]); - } - hal_info(GREEN"[CEC] send message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n"NORMAL,ToString((cec_logical_address)txmessage.initiator), txmessage.destination == 0xf ? "all" : ToString((cec_logical_address)txmessage.destination), txmessage.initiator, txmessage.destination, ToString((cec_opcode)txmessage.data[0]), str); - - if (fallback) - { - struct cec_msg msg; - cec_msg_init(&msg, txmessage.initiator, txmessage.destination); - memcpy(&msg.msg[1], txmessage.data, txmessage.length); - msg.len = txmessage.length + 1; - ioctl(hdmiFd, CEC_TRANSMIT, &msg); - } - else - { - struct cec_message_fb message; - message.address = txmessage.destination; - message.length = txmessage.length; - memcpy(&message.data, txmessage.data, txmessage.length); - ::write(hdmiFd, &message, 2 + message.length); - } - - usleep(sleeptime * 10000); - } -} - -void hdmi_cec::SetCECAutoStandby(bool state) -{ - standby_cec_activ = state; -} - -void hdmi_cec::SetCECAutoView(bool state) -{ - autoview_cec_activ = state; -} - -void hdmi_cec::SetCECState(bool state) -{ - struct cec_message message; - - standby = state; - - if ((standby_cec_activ) && state) - { - message.initiator = logicalAddress; - message.destination = CEC_OP_PRIM_DEVTYPE_TV; - message.data[0] = CEC_MSG_STANDBY; - message.length = 1; - SendCECMessage(message); - - message.initiator = logicalAddress; - message.destination = CEC_OP_PRIM_DEVTYPE_TV; - message.data[0] = CEC_MSG_GIVE_DEVICE_POWER_STATUS; - message.length = 1; - SendCECMessage(message); - } - - if ((autoview_cec_activ) && !state) - { - message.initiator = logicalAddress; - message.destination = CEC_OP_PRIM_DEVTYPE_TV; - message.data[0] = CEC_MSG_GET_CEC_VERSION; - message.length = 1; - SendCECMessage(message); - - message.initiator = logicalAddress; - message.destination = CEC_OP_PRIM_DEVTYPE_TV; - message.data[0] = CEC_MSG_GIVE_DEVICE_POWER_STATUS; - message.length = 1; - SendCECMessage(message); - -#if BOXMODEL_VUPLUS_ALL - int cnt = 0; - - while (tv_off && (cnt < 5)) - { -#endif - - message.initiator = logicalAddress; - message.destination = CEC_OP_PRIM_DEVTYPE_TV; - message.data[0] = CEC_MSG_IMAGE_VIEW_ON; - message.length = 1; - SendCECMessage(message); - - message.initiator = logicalAddress; - message.destination = CEC_OP_PRIM_DEVTYPE_TV; - message.data[0] = CEC_MSG_GIVE_DEVICE_POWER_STATUS; - message.length = 1; - SendCECMessage(message); - -#if BOXMODEL_VUPLUS_ALL - cnt++; - } -#endif - - GetCECAddressInfo(); - - message.initiator = logicalAddress; - message.destination = CEC_LOG_ADDR_BROADCAST; - message.data[0] = CEC_MSG_ACTIVE_SOURCE; - message.data[1] = physicalAddress[0]; - message.data[2] = physicalAddress[1]; - message.length = 3; - SendCECMessage(message); - - message.initiator = logicalAddress; - message.destination = CEC_LOG_ADDR_BROADCAST; - message.data[0] = CEC_OPCODE_SET_OSD_NAME; - message.data[1] = 0x6e; //n - message.data[2] = 0x65; //e - message.data[3] = 0x75; //u - message.data[4] = 0x74; //t - message.data[5] = 0x72; //r - message.data[6] = 0x69; //i - message.data[7] = 0x6e; //n - message.data[8] = 0x6f; //o - message.length = 9; - SendCECMessage(message); - - request_audio_status(); - } - -} - -long hdmi_cec::translateKey(unsigned char code) -{ - long key = 0; - switch (code) - { - case CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL: - key = KEY_MENU; - break; - case CEC_USER_CONTROL_CODE_NUMBER0: - key = KEY_0; - break; - case CEC_USER_CONTROL_CODE_NUMBER1: - key = KEY_1; - break; - case CEC_USER_CONTROL_CODE_NUMBER2: - key = KEY_2; - break; - case CEC_USER_CONTROL_CODE_NUMBER3: - key = KEY_3; - break; - case CEC_USER_CONTROL_CODE_NUMBER4: - key = KEY_4; - break; - case CEC_USER_CONTROL_CODE_NUMBER5: - key = KEY_5; - break; - case CEC_USER_CONTROL_CODE_NUMBER6: - key = KEY_6; - break; - case CEC_USER_CONTROL_CODE_NUMBER7: - key = KEY_7; - break; - case CEC_USER_CONTROL_CODE_NUMBER8: - key = KEY_8; - break; - case CEC_USER_CONTROL_CODE_NUMBER9: - key = KEY_9; - break; - case CEC_USER_CONTROL_CODE_CHANNEL_UP: - key = KEY_CHANNELUP; - break; - case CEC_USER_CONTROL_CODE_CHANNEL_DOWN: - key = KEY_CHANNELDOWN; - break; - case CEC_USER_CONTROL_CODE_PLAY: - key = KEY_PLAY; - break; - case CEC_USER_CONTROL_CODE_STOP: - key = KEY_STOP; - break; - case CEC_USER_CONTROL_CODE_PAUSE: - key = KEY_PAUSE; - break; - case CEC_USER_CONTROL_CODE_RECORD: - key = KEY_RECORD; - break; - case CEC_USER_CONTROL_CODE_REWIND: - key = KEY_REWIND; - break; - case CEC_USER_CONTROL_CODE_FAST_FORWARD: - key = KEY_FASTFORWARD; - break; - case CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE: - key = KEY_INFO; - break; - case CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING: - key = KEY_PROGRAM; - break; - case CEC_USER_CONTROL_CODE_PLAY_FUNCTION: - key = KEY_PLAY; - break; - case CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION: - key = KEY_PLAYPAUSE; - break; - case CEC_USER_CONTROL_CODE_RECORD_FUNCTION: - key = KEY_RECORD; - break; - case CEC_USER_CONTROL_CODE_STOP_FUNCTION: - key = KEY_STOP; - break; - case CEC_USER_CONTROL_CODE_SELECT: - key = KEY_OK; - break; - case CEC_USER_CONTROL_CODE_LEFT: - key = KEY_LEFT; - break; - case CEC_USER_CONTROL_CODE_RIGHT: - key = KEY_RIGHT; - break; - case CEC_USER_CONTROL_CODE_UP: - key = KEY_UP; - break; - case CEC_USER_CONTROL_CODE_DOWN: - key = KEY_DOWN; - break; - case CEC_USER_CONTROL_CODE_EXIT: - key = KEY_EXIT; - break; - case CEC_USER_CONTROL_CODE_F2_RED: - key = KEY_RED; - break; - case CEC_USER_CONTROL_CODE_F3_GREEN: - key = KEY_GREEN; - break; - case CEC_USER_CONTROL_CODE_F4_YELLOW: - key = KEY_YELLOW; - break; - case CEC_USER_CONTROL_CODE_F1_BLUE: - key = KEY_BLUE; - break; - default: - key = KEY_MENU; - break; - } - return key; -} - -bool hdmi_cec::Start() -{ - if (running) - return false; - - if (hdmiFd == -1) - return false; - - running = true; - OpenThreads::Thread::setSchedulePriority(THREAD_PRIORITY_MIN); - return (OpenThreads::Thread::start() == 0); -} - -bool hdmi_cec::Stop() -{ - if (!running) - return false; - - running = false; - - OpenThreads::Thread::cancel(); - - if (hdmiFd >= 0) - { - close(hdmiFd); - hdmiFd = -1; - } - - return (OpenThreads::Thread::join() == 0); -} - -void hdmi_cec::run() -{ - OpenThreads::Thread::setCancelModeAsynchronous(); - int n; - int epollfd = epoll_create1(0); - struct epoll_event event; - event.data.fd = hdmiFd; - event.events = EPOLLIN; - - epoll_ctl(epollfd, EPOLL_CTL_ADD, hdmiFd, &event); - - std::array events; - - while (running) - { - n = epoll_wait(epollfd, events.data(), EPOLL_MAX_EVENTS, EPOLL_WAIT_TIMEOUT); - for (int i = 0; i < n; ++i) - { - if (events[i].events & EPOLLIN) - Receive(events[i].events); - } - } -} - -void hdmi_cec::Receive(int what) -{ - if (what & EPOLLIN) - { - - bool hasdata = false; - struct cec_message rxmessage; - struct cec_message txmessage; - - if (fallback) - { - struct cec_msg msg; - if (::ioctl(hdmiFd, CEC_RECEIVE, &msg) >= 0) - { - rxmessage.length = msg.len - 1; - rxmessage.initiator = cec_msg_initiator(&msg); - rxmessage.destination = cec_msg_destination(&msg); - rxmessage.opcode = cec_msg_opcode(&msg); - memcpy(&rxmessage.data, &msg.msg[1], rxmessage.length); - hasdata = true; - } - } - else - { - struct cec_message_fb rx_message; - if (::read(hdmiFd, &rx_message, 2) == 2) - { - if (::read(hdmiFd, &rx_message.data, rx_message.length) == rx_message.length) - { - rxmessage.length = rx_message.length; - rxmessage.initiator = rx_message.address; - rxmessage.destination = logicalAddress; - rxmessage.opcode = rx_message.data[0]; - memcpy(&rxmessage.data, rx_message.data, rx_message.length); - hasdata = true; - } - } - } - - if (hasdata) - { - bool keypressed = false; - static unsigned char pressedkey = 0; - - char str[rxmessage.length*6]; - for (int i = 0; i < rxmessage.length; i++) - { - sprintf(str+(i*6),"[0x%02X]", rxmessage.data[i]); - } - hal_info(GREEN"[CEC] received message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n"NORMAL,ToString((cec_logical_address)rxmessage.initiator), rxmessage.destination == 0xf ? "all" : ToString((cec_logical_address)rxmessage.destination), rxmessage.initiator, rxmessage.destination, ToString((cec_opcode)rxmessage.opcode), str); - - switch (rxmessage.opcode) - { - //case CEC_OPCODE_ACTIVE_SOURCE: - case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: - { - txmessage.destination = CEC_LOG_ADDR_BROADCAST; //rxmessage.initiator; - txmessage.initiator = logicalAddress; //rxmessage.destination; - txmessage.data[0] = CEC_MSG_ACTIVE_SOURCE; - txmessage.data[1] = physicalAddress[0]; - txmessage.data[2] = physicalAddress[1]; - txmessage.length = 3; - if (!standby) - SendCECMessage(txmessage); - } - case CEC_OPCODE_REPORT_AUDIO_STATUS: - { - muted = ((rxmessage.data[1] & 0x80) == 0x80); - volume = ((rxmessage.data[1] & 0x7F) / 127.0) * 100.0; - if (muted) - hal_info(GREEN"[CEC] %s volume muted\n"NORMAL, ToString((cec_logical_address)rxmessage.initiator)); - else - hal_info(GREEN"[CEC] %s volume %d \n"NORMAL, ToString((cec_logical_address)rxmessage.initiator), volume); - break; - } - case CEC_OPCODE_DEVICE_VENDOR_ID: - case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: - { - uint64_t iVendorId = ((uint64_t)rxmessage.data[1] << 16) + - ((uint64_t)rxmessage.data[2] << 8) + - (uint64_t)rxmessage.data[3]; - hal_info(GREEN"[CEC] decoded message '%s' (%s)\n"NORMAL, ToString((cec_opcode)rxmessage.opcode), ToString((cec_vendor_id)iVendorId)); - break; - } - case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: - { - txmessage.destination = rxmessage.initiator; - txmessage.initiator = rxmessage.destination; - txmessage.data[0] = GetResponseOpcode((cec_opcode)rxmessage.opcode); - txmessage.data[1] = standby ? CEC_POWER_STATUS_STANDBY : CEC_POWER_STATUS_ON; - txmessage.length = 2; - SendCECMessage(txmessage); - break; - } - case CEC_OPCODE_REPORT_POWER_STATUS: - { - if ((rxmessage.data[1] == CEC_POWER_STATUS_ON) || (rxmessage.data[1] == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)) - { - hal_info(GREEN"[CEC] %s reporting state on (%d)\n"NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); - if (rxmessage.initiator == CEC_OP_PRIM_DEVTYPE_TV) - tv_off = false; - } else { - hal_info(GREEN"[CEC] %s reporting state off (%d)\n"NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); - if (rxmessage.initiator == CEC_OP_PRIM_DEVTYPE_TV) - tv_off = true; - } - break; - } - case CEC_OPCODE_STANDBY: - { - if (rxmessage.initiator == CEC_OP_PRIM_DEVTYPE_TV) - tv_off = true; - break; - } - case CEC_OPCODE_USER_CONTROL_PRESSED: /* key pressed */ - { - keypressed = true; - pressedkey = rxmessage.data[1]; - } // fall through - case CEC_OPCODE_USER_CONTROL_RELEASE: /* key released */ - { - long code = translateKey(pressedkey); - hal_info(GREEN"[CEC] decoded key %s (%ld)\n"NORMAL,ToString((cec_user_control_code)pressedkey), code); - handleCode(code,keypressed); - break; - } - } - } - } -} - -void hdmi_cec::handleCode(long code, bool keypressed) -{ - int evd = open(RC_DEVICE, O_RDWR); - if (evd < 0) - { - hal_info(RED"[CEC] opening " RC_DEVICE " failed"NORMAL); - return; - } - if (keypressed) - { - if (rc_send(evd, code, CEC_KEY_PRESSED) < 0) - { - hal_info(RED"[CEC] writing 'KEY_PRESSED' event failed"NORMAL); - close(evd); - return; - } - rc_sync(evd); - } - else - { - if (rc_send(evd, code, CEC_KEY_RELEASED) < 0) - { - hal_info(RED"[CEC] writing 'KEY_RELEASED' event failed"NORMAL); - close(evd); - return; - } - rc_sync(evd); - } - close(evd); -} - -int hdmi_cec::rc_send(int fd, unsigned int code, unsigned int value) -{ - struct input_event ev; - - ev.type = EV_KEY; - ev.code = code; - ev.value = value; - return write(fd, &ev, sizeof(ev)); -} - -void hdmi_cec::rc_sync(int fd) -{ - struct input_event ev; - - gettimeofday(&ev.time, NULL); - ev.type = EV_SYN; - ev.code = SYN_REPORT; - ev.value = 0; - write(fd, &ev, sizeof(ev)); -} - -void hdmi_cec::send_key(unsigned char key, unsigned char destination) -{ - struct cec_message txmessage; - txmessage.destination = destination; - txmessage.initiator = logicalAddress; - txmessage.data[0] = CEC_OPCODE_USER_CONTROL_PRESSED; - txmessage.data[1] = key; - txmessage.length = 2; - SendCECMessage(txmessage, 1); - - txmessage.destination = destination; - txmessage.initiator = logicalAddress; - txmessage.data[0] = CEC_OPCODE_USER_CONTROL_RELEASE; - txmessage.length = 1; - SendCECMessage(txmessage, 0); -} - -void hdmi_cec::request_audio_status() -{ - struct cec_message txmessage; - txmessage.destination = audio_destination; - txmessage.initiator = logicalAddress; - txmessage.data[0] = CEC_OPCODE_GIVE_AUDIO_STATUS; - txmessage.length = 1; - SendCECMessage(txmessage, 0); -} - -void hdmi_cec::vol_up() -{ - send_key(CEC_USER_CONTROL_CODE_VOLUME_UP, audio_destination); - request_audio_status(); -} -void hdmi_cec::vol_down() -{ - send_key(CEC_USER_CONTROL_CODE_VOLUME_DOWN, audio_destination); - request_audio_status(); -} -void hdmi_cec::toggle_mute() -{ - send_key(CEC_USER_CONTROL_CODE_MUTE, audio_destination); - request_audio_status(); -} - -void hdmi_cec::SetAudioDestination(int audio_dest) -{ - switch(audio_dest) - { - case 2: - audio_destination = CEC_OP_PRIM_DEVTYPE_TV; - break; - case 1: - default: - audio_destination = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM; - break; - } -} - diff --git a/libmipsbox/hdmi_cec.cpp b/libmipsbox/hdmi_cec.cpp new file mode 120000 index 0000000..7cf1426 --- /dev/null +++ b/libmipsbox/hdmi_cec.cpp @@ -0,0 +1 @@ +../libarmbox/hdmi_cec.cpp \ No newline at end of file diff --git a/libmipsbox/hdmi_cec.h b/libmipsbox/hdmi_cec.h deleted file mode 100644 index 681cc75..0000000 --- a/libmipsbox/hdmi_cec.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef __HDMI_CEC_H__ -#define __HDMI_CEC_H__ - -/* - Copyright (C) 2018-2021 TangoCash - - License: GPLv2 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include -#include - -#include "video_lib.h" - -struct cec_message -{ - unsigned char initiator; - unsigned char destination; - unsigned char opcode; - unsigned char data[256]; - unsigned char length; -} __attribute__((packed)); - -struct cec_message_fb -{ - unsigned char address; - unsigned char length; - unsigned char data[256]; -} __attribute__((packed)); - -struct addressinfo -{ - unsigned char logical; - unsigned char physical[2]; - unsigned char type; -}; - -enum -{ - CEC_KEY_RELEASED = 0, - CEC_KEY_PRESSED, - CEC_KEY_AUTOREPEAT -}; - -class hdmi_cec : public OpenThreads::Thread -{ -private: - hdmi_cec(); - static hdmi_cec *hdmi_cec_instance; - void run(); - bool Start(); - bool Stop(); - void Receive(int what); - unsigned char physicalAddress[2]; - bool autoview_cec_activ; - unsigned char deviceType, logicalAddress; - int hdmiFd; - long translateKey(unsigned char code); - void handleCode(long code, bool keypressed); - int rc_send(int fd, unsigned int code, unsigned int value); - void rc_sync(int fd); - bool standby; - void send_key(unsigned char key, unsigned char destination); - void request_audio_status(); - bool muted; - int volume; - bool fallback; - bool tv_off; - unsigned char audio_destination; -protected: - bool running; -public: - ~hdmi_cec(); - static hdmi_cec* getInstance(); - bool SetCECMode(VIDEO_HDMI_CEC_MODE); - void SetCECAutoView(bool); - void SetCECAutoStandby(bool); - void GetCECAddressInfo(); - void SendCECMessage(struct cec_message &message, int sleeptime = 10); - void SetCECState(bool state); - void ReportPhysicalAddress(); - bool standby_cec_activ; - void vol_up(); - void vol_down(); - void toggle_mute(); - int GetVolume() - { - return volume; - }; - bool isMuted() - { - return muted; - }; - int GetAudioDestination() - { - return (int)audio_destination; - } - void SetAudioDestination(int audio_dest); -}; - -#endif // __HDMI_CEC_H__ diff --git a/libmipsbox/hdmi_cec.h b/libmipsbox/hdmi_cec.h new file mode 120000 index 0000000..20ec29c --- /dev/null +++ b/libmipsbox/hdmi_cec.h @@ -0,0 +1 @@ +../libarmbox/hdmi_cec.h \ No newline at end of file diff --git a/libmipsbox/hdmi_cec_types.h b/libmipsbox/hdmi_cec_types.h deleted file mode 100644 index 9600222..0000000 --- a/libmipsbox/hdmi_cec_types.h +++ /dev/null @@ -1,713 +0,0 @@ -#ifndef __HDMI_CEC_TYPES_H__ -#define __HDMI_CEC_TYPES_H__ - -typedef enum cec_vendor_id -{ - CEC_VENDOR_TOSHIBA = 0x000039, - CEC_VENDOR_SAMSUNG = 0x0000F0, - CEC_VENDOR_DENON = 0x0005CD, - CEC_VENDOR_MARANTZ = 0x000678, - CEC_VENDOR_LOEWE = 0x000982, - CEC_VENDOR_ONKYO = 0x0009B0, - CEC_VENDOR_MEDION = 0x000CB8, - CEC_VENDOR_TOSHIBA2 = 0x000CE7, - CEC_VENDOR_PULSE_EIGHT = 0x001582, - CEC_VENDOR_HARMAN_KARDON2 = 0x001950, - CEC_VENDOR_GOOGLE = 0x001A11, - CEC_VENDOR_AKAI = 0x0020C7, - CEC_VENDOR_AOC = 0x002467, - CEC_VENDOR_PANASONIC = 0x008045, - CEC_VENDOR_PHILIPS = 0x00903E, - CEC_VENDOR_DAEWOO = 0x009053, - CEC_VENDOR_YAMAHA = 0x00A0DE, - CEC_VENDOR_GRUNDIG = 0x00D0D5, - CEC_VENDOR_PIONEER = 0x00E036, - CEC_VENDOR_LG = 0x00E091, - CEC_VENDOR_SHARP = 0x08001F, - CEC_VENDOR_SONY = 0x080046, - CEC_VENDOR_BROADCOM = 0x18C086, - CEC_VENDOR_SHARP2 = 0x534850, - CEC_VENDOR_VIZIO = 0x6B746D, - CEC_VENDOR_BENQ = 0x8065E9, - CEC_VENDOR_HARMAN_KARDON = 0x9C645E, - CEC_VENDOR_UNKNOWN = 0 -} cec_vendor_id; - -typedef enum cec_user_control_code -{ - CEC_USER_CONTROL_CODE_SELECT = 0x00, - CEC_USER_CONTROL_CODE_UP = 0x01, - CEC_USER_CONTROL_CODE_DOWN = 0x02, - CEC_USER_CONTROL_CODE_LEFT = 0x03, - CEC_USER_CONTROL_CODE_RIGHT = 0x04, - CEC_USER_CONTROL_CODE_RIGHT_UP = 0x05, - CEC_USER_CONTROL_CODE_RIGHT_DOWN = 0x06, - CEC_USER_CONTROL_CODE_LEFT_UP = 0x07, - CEC_USER_CONTROL_CODE_LEFT_DOWN = 0x08, - CEC_USER_CONTROL_CODE_ROOT_MENU = 0x09, - CEC_USER_CONTROL_CODE_SETUP_MENU = 0x0A, - CEC_USER_CONTROL_CODE_CONTENTS_MENU = 0x0B, - CEC_USER_CONTROL_CODE_FAVORITE_MENU = 0x0C, - CEC_USER_CONTROL_CODE_EXIT = 0x0D, - // reserved: 0x0E, 0x0F - CEC_USER_CONTROL_CODE_TOP_MENU = 0x10, - CEC_USER_CONTROL_CODE_DVD_MENU = 0x11, - // reserved: 0x12 ... 0x1C - CEC_USER_CONTROL_CODE_NUMBER_ENTRY_MODE = 0x1D, - CEC_USER_CONTROL_CODE_NUMBER11 = 0x1E, - CEC_USER_CONTROL_CODE_NUMBER12 = 0x1F, - CEC_USER_CONTROL_CODE_NUMBER0 = 0x20, - CEC_USER_CONTROL_CODE_NUMBER1 = 0x21, - CEC_USER_CONTROL_CODE_NUMBER2 = 0x22, - CEC_USER_CONTROL_CODE_NUMBER3 = 0x23, - CEC_USER_CONTROL_CODE_NUMBER4 = 0x24, - CEC_USER_CONTROL_CODE_NUMBER5 = 0x25, - CEC_USER_CONTROL_CODE_NUMBER6 = 0x26, - CEC_USER_CONTROL_CODE_NUMBER7 = 0x27, - CEC_USER_CONTROL_CODE_NUMBER8 = 0x28, - CEC_USER_CONTROL_CODE_NUMBER9 = 0x29, - CEC_USER_CONTROL_CODE_DOT = 0x2A, - CEC_USER_CONTROL_CODE_ENTER = 0x2B, - CEC_USER_CONTROL_CODE_CLEAR = 0x2C, - CEC_USER_CONTROL_CODE_NEXT_FAVORITE = 0x2F, - CEC_USER_CONTROL_CODE_CHANNEL_UP = 0x30, - CEC_USER_CONTROL_CODE_CHANNEL_DOWN = 0x31, - CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL = 0x32, - CEC_USER_CONTROL_CODE_SOUND_SELECT = 0x33, - CEC_USER_CONTROL_CODE_INPUT_SELECT = 0x34, - CEC_USER_CONTROL_CODE_DISPLAY_INFORMATION = 0x35, - CEC_USER_CONTROL_CODE_HELP = 0x36, - CEC_USER_CONTROL_CODE_PAGE_UP = 0x37, - CEC_USER_CONTROL_CODE_PAGE_DOWN = 0x38, - // reserved: 0x39 ... 0x3F - CEC_USER_CONTROL_CODE_POWER = 0x40, - CEC_USER_CONTROL_CODE_VOLUME_UP = 0x41, - CEC_USER_CONTROL_CODE_VOLUME_DOWN = 0x42, - CEC_USER_CONTROL_CODE_MUTE = 0x43, - CEC_USER_CONTROL_CODE_PLAY = 0x44, - CEC_USER_CONTROL_CODE_STOP = 0x45, - CEC_USER_CONTROL_CODE_PAUSE = 0x46, - CEC_USER_CONTROL_CODE_RECORD = 0x47, - CEC_USER_CONTROL_CODE_REWIND = 0x48, - CEC_USER_CONTROL_CODE_FAST_FORWARD = 0x49, - CEC_USER_CONTROL_CODE_EJECT = 0x4A, - CEC_USER_CONTROL_CODE_FORWARD = 0x4B, - CEC_USER_CONTROL_CODE_BACKWARD = 0x4C, - CEC_USER_CONTROL_CODE_STOP_RECORD = 0x4D, - CEC_USER_CONTROL_CODE_PAUSE_RECORD = 0x4E, - // reserved: 0x4F - CEC_USER_CONTROL_CODE_ANGLE = 0x50, - CEC_USER_CONTROL_CODE_SUB_PICTURE = 0x51, - CEC_USER_CONTROL_CODE_VIDEO_ON_DEMAND = 0x52, - CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE = 0x53, - CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING = 0x54, - CEC_USER_CONTROL_CODE_INITIAL_CONFIGURATION = 0x55, - CEC_USER_CONTROL_CODE_SELECT_BROADCAST_TYPE = 0x56, - CEC_USER_CONTROL_CODE_SELECT_SOUND_PRESENTATION = 0x57, - // reserved: 0x58 ... 0x5F - CEC_USER_CONTROL_CODE_PLAY_FUNCTION = 0x60, - CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION = 0x61, - CEC_USER_CONTROL_CODE_RECORD_FUNCTION = 0x62, - CEC_USER_CONTROL_CODE_PAUSE_RECORD_FUNCTION = 0x63, - CEC_USER_CONTROL_CODE_STOP_FUNCTION = 0x64, - CEC_USER_CONTROL_CODE_MUTE_FUNCTION = 0x65, - CEC_USER_CONTROL_CODE_RESTORE_VOLUME_FUNCTION = 0x66, - CEC_USER_CONTROL_CODE_TUNE_FUNCTION = 0x67, - CEC_USER_CONTROL_CODE_SELECT_MEDIA_FUNCTION = 0x68, - CEC_USER_CONTROL_CODE_SELECT_AV_INPUT_FUNCTION = 0x69, - CEC_USER_CONTROL_CODE_SELECT_AUDIO_INPUT_FUNCTION = 0x6A, - CEC_USER_CONTROL_CODE_POWER_TOGGLE_FUNCTION = 0x6B, - CEC_USER_CONTROL_CODE_POWER_OFF_FUNCTION = 0x6C, - CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION = 0x6D, - // reserved: 0x6E ... 0x70 - CEC_USER_CONTROL_CODE_F1_BLUE = 0x71, - CEC_USER_CONTROL_CODE_F2_RED = 0X72, - CEC_USER_CONTROL_CODE_F3_GREEN = 0x73, - CEC_USER_CONTROL_CODE_F4_YELLOW = 0x74, - CEC_USER_CONTROL_CODE_F5 = 0x75, - CEC_USER_CONTROL_CODE_DATA = 0x76, - // reserved: 0x77 ... 0xFF - CEC_USER_CONTROL_CODE_AN_RETURN = 0x91, // return (Samsung) - CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST = 0x96, // channels list (Samsung) - CEC_USER_CONTROL_CODE_MAX = 0x96, - CEC_USER_CONTROL_CODE_UNKNOWN = 0xFF -} cec_user_control_code; - -typedef enum cec_opcode -{ - CEC_OPCODE_ACTIVE_SOURCE = 0x82, - CEC_OPCODE_IMAGE_VIEW_ON = 0x04, - CEC_OPCODE_TEXT_VIEW_ON = 0x0D, - CEC_OPCODE_INACTIVE_SOURCE = 0x9D, - CEC_OPCODE_REQUEST_ACTIVE_SOURCE = 0x85, - CEC_OPCODE_ROUTING_CHANGE = 0x80, - CEC_OPCODE_ROUTING_INFORMATION = 0x81, - CEC_OPCODE_SET_STREAM_PATH = 0x86, - CEC_OPCODE_STANDBY = 0x36, - CEC_OPCODE_RECORD_OFF = 0x0B, - CEC_OPCODE_RECORD_ON = 0x09, - CEC_OPCODE_RECORD_STATUS = 0x0A, - CEC_OPCODE_RECORD_TV_SCREEN = 0x0F, - CEC_OPCODE_CLEAR_ANALOGUE_TIMER = 0x33, - CEC_OPCODE_CLEAR_DIGITAL_TIMER = 0x99, - CEC_OPCODE_CLEAR_EXTERNAL_TIMER = 0xA1, - CEC_OPCODE_SET_ANALOGUE_TIMER = 0x34, - CEC_OPCODE_SET_DIGITAL_TIMER = 0x97, - CEC_OPCODE_SET_EXTERNAL_TIMER = 0xA2, - CEC_OPCODE_SET_TIMER_PROGRAM_TITLE = 0x67, - CEC_OPCODE_TIMER_CLEARED_STATUS = 0x43, - CEC_OPCODE_TIMER_STATUS = 0x35, - CEC_OPCODE_CEC_VERSION = 0x9E, - CEC_OPCODE_GET_CEC_VERSION = 0x9F, - CEC_OPCODE_GIVE_PHYSICAL_ADDRESS = 0x83, - CEC_OPCODE_GET_MENU_LANGUAGE = 0x91, - CEC_OPCODE_REPORT_PHYSICAL_ADDRESS = 0x84, - CEC_OPCODE_SET_MENU_LANGUAGE = 0x32, - CEC_OPCODE_DECK_CONTROL = 0x42, - CEC_OPCODE_DECK_STATUS = 0x1B, - CEC_OPCODE_GIVE_DECK_STATUS = 0x1A, - CEC_OPCODE_PLAY = 0x41, - CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS = 0x08, - CEC_OPCODE_SELECT_ANALOGUE_SERVICE = 0x92, - CEC_OPCODE_SELECT_DIGITAL_SERVICE = 0x93, - CEC_OPCODE_TUNER_DEVICE_STATUS = 0x07, - CEC_OPCODE_TUNER_STEP_DECREMENT = 0x06, - CEC_OPCODE_TUNER_STEP_INCREMENT = 0x05, - CEC_OPCODE_DEVICE_VENDOR_ID = 0x87, - CEC_OPCODE_GIVE_DEVICE_VENDOR_ID = 0x8C, - CEC_OPCODE_VENDOR_COMMAND = 0x89, - CEC_OPCODE_VENDOR_COMMAND_WITH_ID = 0xA0, - CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN = 0x8A, - CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP = 0x8B, - CEC_OPCODE_SET_OSD_STRING = 0x64, - CEC_OPCODE_GIVE_OSD_NAME = 0x46, - CEC_OPCODE_SET_OSD_NAME = 0x47, - CEC_OPCODE_MENU_REQUEST = 0x8D, - CEC_OPCODE_MENU_STATUS = 0x8E, - CEC_OPCODE_USER_CONTROL_PRESSED = 0x44, - CEC_OPCODE_USER_CONTROL_RELEASE = 0x45, - CEC_OPCODE_GIVE_DEVICE_POWER_STATUS = 0x8F, - CEC_OPCODE_REPORT_POWER_STATUS = 0x90, - CEC_OPCODE_FEATURE_ABORT = 0x00, - CEC_OPCODE_ABORT = 0xFF, - CEC_OPCODE_GIVE_AUDIO_STATUS = 0x71, - CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS = 0x7D, - CEC_OPCODE_REPORT_AUDIO_STATUS = 0x7A, - CEC_OPCODE_SET_SYSTEM_AUDIO_MODE = 0x72, - CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST = 0x70, - CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS = 0x7E, - CEC_OPCODE_SET_AUDIO_RATE = 0x9A, - - /* CEC 1.4 */ - CEC_OPCODE_START_ARC = 0xC0, - CEC_OPCODE_REPORT_ARC_STARTED = 0xC1, - CEC_OPCODE_REPORT_ARC_ENDED = 0xC2, - CEC_OPCODE_REQUEST_ARC_START = 0xC3, - CEC_OPCODE_REQUEST_ARC_END = 0xC4, - CEC_OPCODE_END_ARC = 0xC5, - CEC_OPCODE_CDC = 0xF8, - /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */ - CEC_OPCODE_NONE = 0xFD -} cec_opcode; - -typedef enum cec_logical_address -{ - CECDEVICE_UNKNOWN = -1, //not a valid logical address - CECDEVICE_TV = 0, - CECDEVICE_RECORDINGDEVICE1 = 1, - CECDEVICE_RECORDINGDEVICE2 = 2, - CECDEVICE_TUNER1 = 3, - CECDEVICE_PLAYBACKDEVICE1 = 4, - CECDEVICE_AUDIOSYSTEM = 5, - CECDEVICE_TUNER2 = 6, - CECDEVICE_TUNER3 = 7, - CECDEVICE_PLAYBACKDEVICE2 = 8, - CECDEVICE_RECORDINGDEVICE3 = 9, - CECDEVICE_TUNER4 = 10, - CECDEVICE_PLAYBACKDEVICE3 = 11, - CECDEVICE_RESERVED1 = 12, - CECDEVICE_RESERVED2 = 13, - CECDEVICE_FREEUSE = 14, - CECDEVICE_UNREGISTERED = 15, - CECDEVICE_BROADCAST = 15 -} cec_logical_address; - -typedef enum cec_power_status -{ - CEC_POWER_STATUS_ON = 0x00, - CEC_POWER_STATUS_STANDBY = 0x01, - CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON = 0x02, - CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY = 0x03, - CEC_POWER_STATUS_UNKNOWN = 0x99 -} cec_power_status; - -static const char *ToString(const cec_opcode opcode) -{ - switch (opcode) - { - case CEC_OPCODE_ACTIVE_SOURCE: - return "active source"; - case CEC_OPCODE_IMAGE_VIEW_ON: - return "image view on"; - case CEC_OPCODE_TEXT_VIEW_ON: - return "text view on"; - case CEC_OPCODE_INACTIVE_SOURCE: - return "inactive source"; - case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: - return "request active source"; - case CEC_OPCODE_ROUTING_CHANGE: - return "routing change"; - case CEC_OPCODE_ROUTING_INFORMATION: - return "routing information"; - case CEC_OPCODE_SET_STREAM_PATH: - return "set stream path"; - case CEC_OPCODE_STANDBY: - return "standby"; - case CEC_OPCODE_RECORD_OFF: - return "record off"; - case CEC_OPCODE_RECORD_ON: - return "record on"; - case CEC_OPCODE_RECORD_STATUS: - return "record status"; - case CEC_OPCODE_RECORD_TV_SCREEN: - return "record tv screen"; - case CEC_OPCODE_CLEAR_ANALOGUE_TIMER: - return "clear analogue timer"; - case CEC_OPCODE_CLEAR_DIGITAL_TIMER: - return "clear digital timer"; - case CEC_OPCODE_CLEAR_EXTERNAL_TIMER: - return "clear external timer"; - case CEC_OPCODE_SET_ANALOGUE_TIMER: - return "set analogue timer"; - case CEC_OPCODE_SET_DIGITAL_TIMER: - return "set digital timer"; - case CEC_OPCODE_SET_EXTERNAL_TIMER: - return "set external timer"; - case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE: - return "set timer program title"; - case CEC_OPCODE_TIMER_CLEARED_STATUS: - return "timer cleared status"; - case CEC_OPCODE_TIMER_STATUS: - return "timer status"; - case CEC_OPCODE_CEC_VERSION: - return "cec version"; - case CEC_OPCODE_GET_CEC_VERSION: - return "get cec version"; - case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: - return "give physical address"; - case CEC_OPCODE_GET_MENU_LANGUAGE: - return "get menu language"; - case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: - return "report physical address"; - case CEC_OPCODE_SET_MENU_LANGUAGE: - return "set menu language"; - case CEC_OPCODE_DECK_CONTROL: - return "deck control"; - case CEC_OPCODE_DECK_STATUS: - return "deck status"; - case CEC_OPCODE_GIVE_DECK_STATUS: - return "give deck status"; - case CEC_OPCODE_PLAY: - return "play"; - case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: - return "give tuner status"; - case CEC_OPCODE_SELECT_ANALOGUE_SERVICE: - return "select analogue service"; - case CEC_OPCODE_SELECT_DIGITAL_SERVICE: - return "set digital service"; - case CEC_OPCODE_TUNER_DEVICE_STATUS: - return "tuner device status"; - case CEC_OPCODE_TUNER_STEP_DECREMENT: - return "tuner step decrement"; - case CEC_OPCODE_TUNER_STEP_INCREMENT: - return "tuner step increment"; - case CEC_OPCODE_DEVICE_VENDOR_ID: - return "device vendor id"; - case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: - return "give device vendor id"; - case CEC_OPCODE_VENDOR_COMMAND: - return "vendor command"; - case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: - return "vendor command with id"; - case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN: - return "vendor remote button down"; - case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP: - return "vendor remote button up"; - case CEC_OPCODE_SET_OSD_STRING: - return "set osd string"; - case CEC_OPCODE_GIVE_OSD_NAME: - return "give osd name"; - case CEC_OPCODE_SET_OSD_NAME: - return "set osd name"; - case CEC_OPCODE_MENU_REQUEST: - return "menu request"; - case CEC_OPCODE_MENU_STATUS: - return "menu status"; - case CEC_OPCODE_USER_CONTROL_PRESSED: - return "user control pressed"; - case CEC_OPCODE_USER_CONTROL_RELEASE: - return "user control release"; - case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: - return "give device power status"; - case CEC_OPCODE_REPORT_POWER_STATUS: - return "report power status"; - case CEC_OPCODE_FEATURE_ABORT: - return "feature abort"; - case CEC_OPCODE_ABORT: - return "abort"; - case CEC_OPCODE_GIVE_AUDIO_STATUS: - return "give audio status"; - case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: - return "give audio mode status"; - case CEC_OPCODE_REPORT_AUDIO_STATUS: - return "report audio status"; - case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: - return "set system audio mode"; - case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: - return "system audio mode request"; - case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: - return "system audio mode status"; - case CEC_OPCODE_SET_AUDIO_RATE: - return "set audio rate"; - case CEC_OPCODE_START_ARC: - return "start ARC"; - case CEC_OPCODE_REPORT_ARC_STARTED: - return "report ARC started"; - case CEC_OPCODE_REPORT_ARC_ENDED: - return "report ARC ended"; - case CEC_OPCODE_REQUEST_ARC_START: - return "request ARC start"; - case CEC_OPCODE_REQUEST_ARC_END: - return "request ARC end"; - case CEC_OPCODE_END_ARC: - return "end ARC"; - case CEC_OPCODE_CDC: - return "CDC"; - case CEC_OPCODE_NONE: - return "poll"; - default: - return "UNKNOWN"; - } -} - -static const char *ToString(const cec_vendor_id vendor) -{ - switch (vendor) - { - case CEC_VENDOR_SAMSUNG: - return "Samsung"; - case CEC_VENDOR_LG: - return "LG"; - case CEC_VENDOR_PANASONIC: - return "Panasonic"; - case CEC_VENDOR_PIONEER: - return "Pioneer"; - case CEC_VENDOR_ONKYO: - return "Onkyo"; - case CEC_VENDOR_YAMAHA: - return "Yamaha"; - case CEC_VENDOR_PHILIPS: - return "Philips"; - case CEC_VENDOR_SONY: - return "Sony"; - case CEC_VENDOR_TOSHIBA: - case CEC_VENDOR_TOSHIBA2: - return "Toshiba"; - case CEC_VENDOR_AKAI: - return "Akai"; - case CEC_VENDOR_AOC: - return "AOC"; - case CEC_VENDOR_BENQ: - return "Benq"; - case CEC_VENDOR_DAEWOO: - return "Daewoo"; - case CEC_VENDOR_GRUNDIG: - return "Grundig"; - case CEC_VENDOR_MEDION: - return "Medion"; - case CEC_VENDOR_SHARP: - case CEC_VENDOR_SHARP2: - return "Sharp"; - case CEC_VENDOR_VIZIO: - return "Vizio"; - case CEC_VENDOR_BROADCOM: - return "Broadcom"; - case CEC_VENDOR_LOEWE: - return "Loewe"; - case CEC_VENDOR_DENON: - return "Denon"; - case CEC_VENDOR_MARANTZ: - return "Marantz"; - case CEC_VENDOR_HARMAN_KARDON: - case CEC_VENDOR_HARMAN_KARDON2: - return "Harman/Kardon"; - case CEC_VENDOR_PULSE_EIGHT: - return "Pulse Eight"; - case CEC_VENDOR_GOOGLE: - return "Google"; - default: - return "Unknown"; - } -} - -static const char *ToString(const cec_user_control_code key) -{ - switch (key) - { - case CEC_USER_CONTROL_CODE_SELECT: - return "select"; - case CEC_USER_CONTROL_CODE_UP: - return "up"; - case CEC_USER_CONTROL_CODE_DOWN: - return "down"; - case CEC_USER_CONTROL_CODE_LEFT: - return "left"; - case CEC_USER_CONTROL_CODE_RIGHT: - return "right"; - case CEC_USER_CONTROL_CODE_RIGHT_UP: - return "right+up"; - case CEC_USER_CONTROL_CODE_RIGHT_DOWN: - return "right+down"; - case CEC_USER_CONTROL_CODE_LEFT_UP: - return "left+up"; - case CEC_USER_CONTROL_CODE_LEFT_DOWN: - return "left+down"; - case CEC_USER_CONTROL_CODE_ROOT_MENU: - return "root menu"; - case CEC_USER_CONTROL_CODE_SETUP_MENU: - return "setup menu"; - case CEC_USER_CONTROL_CODE_CONTENTS_MENU: - return "contents menu"; - case CEC_USER_CONTROL_CODE_FAVORITE_MENU: - return "favourite menu"; - case CEC_USER_CONTROL_CODE_EXIT: - return "exit"; - case CEC_USER_CONTROL_CODE_TOP_MENU: - return "top menu"; - case CEC_USER_CONTROL_CODE_DVD_MENU: - return "dvd menu"; - case CEC_USER_CONTROL_CODE_NUMBER_ENTRY_MODE: - return "number entry mode"; - case CEC_USER_CONTROL_CODE_NUMBER11: - return "11"; - case CEC_USER_CONTROL_CODE_NUMBER12: - return "12"; - case CEC_USER_CONTROL_CODE_NUMBER0: - return "0"; - case CEC_USER_CONTROL_CODE_NUMBER1: - return "1"; - case CEC_USER_CONTROL_CODE_NUMBER2: - return "2"; - case CEC_USER_CONTROL_CODE_NUMBER3: - return "3"; - case CEC_USER_CONTROL_CODE_NUMBER4: - return "4"; - case CEC_USER_CONTROL_CODE_NUMBER5: - return "5"; - case CEC_USER_CONTROL_CODE_NUMBER6: - return "6"; - case CEC_USER_CONTROL_CODE_NUMBER7: - return "7"; - case CEC_USER_CONTROL_CODE_NUMBER8: - return "8"; - case CEC_USER_CONTROL_CODE_NUMBER9: - return "9"; - case CEC_USER_CONTROL_CODE_DOT: - return "."; - case CEC_USER_CONTROL_CODE_ENTER: - return "enter"; - case CEC_USER_CONTROL_CODE_CLEAR: - return "clear"; - case CEC_USER_CONTROL_CODE_NEXT_FAVORITE: - return "next favourite"; - case CEC_USER_CONTROL_CODE_CHANNEL_UP: - return "channel up"; - case CEC_USER_CONTROL_CODE_CHANNEL_DOWN: - return "channel down"; - case CEC_USER_CONTROL_CODE_PREVIOUS_CHANNEL: - return "previous channel"; - case CEC_USER_CONTROL_CODE_SOUND_SELECT: - return "sound select"; - case CEC_USER_CONTROL_CODE_INPUT_SELECT: - return "input select"; - case CEC_USER_CONTROL_CODE_DISPLAY_INFORMATION: - return "display information"; - case CEC_USER_CONTROL_CODE_HELP: - return "help"; - case CEC_USER_CONTROL_CODE_PAGE_UP: - return "page up"; - case CEC_USER_CONTROL_CODE_PAGE_DOWN: - return "page down"; - case CEC_USER_CONTROL_CODE_POWER: - return "power"; - case CEC_USER_CONTROL_CODE_VOLUME_UP: - return "volume up"; - case CEC_USER_CONTROL_CODE_VOLUME_DOWN: - return "volume down"; - case CEC_USER_CONTROL_CODE_MUTE: - return "mute"; - case CEC_USER_CONTROL_CODE_PLAY: - return "play"; - case CEC_USER_CONTROL_CODE_STOP: - return "stop"; - case CEC_USER_CONTROL_CODE_PAUSE: - return "pause"; - case CEC_USER_CONTROL_CODE_RECORD: - return "record"; - case CEC_USER_CONTROL_CODE_REWIND: - return "rewind"; - case CEC_USER_CONTROL_CODE_FAST_FORWARD: - return "Fast forward"; - case CEC_USER_CONTROL_CODE_EJECT: - return "eject"; - case CEC_USER_CONTROL_CODE_FORWARD: - return "forward"; - case CEC_USER_CONTROL_CODE_BACKWARD: - return "backward"; - case CEC_USER_CONTROL_CODE_STOP_RECORD: - return "stop record"; - case CEC_USER_CONTROL_CODE_PAUSE_RECORD: - return "pause record"; - case CEC_USER_CONTROL_CODE_ANGLE: - return "angle"; - case CEC_USER_CONTROL_CODE_SUB_PICTURE: - return "sub picture"; - case CEC_USER_CONTROL_CODE_VIDEO_ON_DEMAND: - return "video on demand"; - case CEC_USER_CONTROL_CODE_ELECTRONIC_PROGRAM_GUIDE: - return "electronic program guide"; - case CEC_USER_CONTROL_CODE_TIMER_PROGRAMMING: - return "timer programming"; - case CEC_USER_CONTROL_CODE_INITIAL_CONFIGURATION: - return "initial configuration"; - case CEC_USER_CONTROL_CODE_SELECT_BROADCAST_TYPE: - return "select broadcast type"; - case CEC_USER_CONTROL_CODE_SELECT_SOUND_PRESENTATION: - return "select sound presentation"; - case CEC_USER_CONTROL_CODE_PLAY_FUNCTION: - return "play (function)"; - case CEC_USER_CONTROL_CODE_PAUSE_PLAY_FUNCTION: - return "pause play (function)"; - case CEC_USER_CONTROL_CODE_RECORD_FUNCTION: - return "record (function)"; - case CEC_USER_CONTROL_CODE_PAUSE_RECORD_FUNCTION: - return "pause record (function)"; - case CEC_USER_CONTROL_CODE_STOP_FUNCTION: - return "stop (function)"; - case CEC_USER_CONTROL_CODE_MUTE_FUNCTION: - return "mute (function)"; - case CEC_USER_CONTROL_CODE_RESTORE_VOLUME_FUNCTION: - return "restore volume"; - case CEC_USER_CONTROL_CODE_TUNE_FUNCTION: - return "tune"; - case CEC_USER_CONTROL_CODE_SELECT_MEDIA_FUNCTION: - return "select media"; - case CEC_USER_CONTROL_CODE_SELECT_AV_INPUT_FUNCTION: - return "select AV input"; - case CEC_USER_CONTROL_CODE_SELECT_AUDIO_INPUT_FUNCTION: - return "select audio input"; - case CEC_USER_CONTROL_CODE_POWER_TOGGLE_FUNCTION: - return "power toggle"; - case CEC_USER_CONTROL_CODE_POWER_OFF_FUNCTION: - return "power off"; - case CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION: - return "power on"; - case CEC_USER_CONTROL_CODE_F1_BLUE: - return "F1 (blue)"; - case CEC_USER_CONTROL_CODE_F2_RED: - return "F2 (red)"; - case CEC_USER_CONTROL_CODE_F3_GREEN: - return "F3 (green)"; - case CEC_USER_CONTROL_CODE_F4_YELLOW: - return "F4 (yellow)"; - case CEC_USER_CONTROL_CODE_F5: - return "F5"; - case CEC_USER_CONTROL_CODE_DATA: - return "data"; - case CEC_USER_CONTROL_CODE_AN_RETURN: - return "return (Samsung)"; - case CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST: - return "channels list (Samsung)"; - default: - return "unknown"; - } -} - -static const char *ToString(cec_logical_address la) -{ - switch (la & 0xf) - { - case CECDEVICE_TV: - return "TV"; - case CECDEVICE_RECORDINGDEVICE1: - return "Recording Device 1"; - case CECDEVICE_RECORDINGDEVICE2: - return "Recording Device 2"; - case CECDEVICE_TUNER1: - return "Tuner 1"; - case CECDEVICE_PLAYBACKDEVICE1: - return "Playback Device 1"; - case CECDEVICE_AUDIOSYSTEM: - return "Audio System"; - case CECDEVICE_TUNER2: - return "Tuner 2"; - case CECDEVICE_TUNER3: - return "Tuner 3"; - case CECDEVICE_PLAYBACKDEVICE2: - return "Playback Device 2"; - case CECDEVICE_RECORDINGDEVICE3: - return "Recording Device 3"; - case CECDEVICE_TUNER4: - return "Tuner 4"; - case CECDEVICE_PLAYBACKDEVICE3: - return "Playback Device 3"; - case CECDEVICE_RESERVED1: - return "Reserved 1"; - case CECDEVICE_RESERVED2: - return "Reserved 2"; - case CECDEVICE_FREEUSE: - return "Free use"; - case CECDEVICE_UNREGISTERED: - default: - return "Unregistered"; - } -} - -static cec_opcode GetResponseOpcode(cec_opcode opcode) -{ - switch (opcode) - { - case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: - return CEC_OPCODE_ACTIVE_SOURCE; - case CEC_OPCODE_GET_CEC_VERSION: - return CEC_OPCODE_CEC_VERSION; - case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: - return CEC_OPCODE_REPORT_PHYSICAL_ADDRESS; - case CEC_OPCODE_GET_MENU_LANGUAGE: - return CEC_OPCODE_SET_MENU_LANGUAGE; - case CEC_OPCODE_GIVE_DECK_STATUS: - return CEC_OPCODE_DECK_STATUS; - case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: - return CEC_OPCODE_TUNER_DEVICE_STATUS; - case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: - return CEC_OPCODE_DEVICE_VENDOR_ID; - case CEC_OPCODE_GIVE_OSD_NAME: - return CEC_OPCODE_SET_OSD_NAME; - case CEC_OPCODE_MENU_REQUEST: - return CEC_OPCODE_MENU_STATUS; - case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: - return CEC_OPCODE_REPORT_POWER_STATUS; - case CEC_OPCODE_GIVE_AUDIO_STATUS: - return CEC_OPCODE_REPORT_AUDIO_STATUS; - case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: - return CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS; - case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: - return CEC_OPCODE_SET_SYSTEM_AUDIO_MODE; - default: - break; - } - - return CEC_OPCODE_NONE; -} - -#endif // __HDMI_CEC_TYPES_H__ diff --git a/libmipsbox/hdmi_cec_types.h b/libmipsbox/hdmi_cec_types.h new file mode 120000 index 0000000..3481cbf --- /dev/null +++ b/libmipsbox/hdmi_cec_types.h @@ -0,0 +1 @@ +../libarmbox/hdmi_cec_types.h \ No newline at end of file diff --git a/libmipsbox/init.cpp b/libmipsbox/init.cpp deleted file mode 100644 index 76190c7..0000000 --- a/libmipsbox/init.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "init.h" -#include "pwrmngr.h" -#include - -#include "hal_debug.h" -#define hal_debug(args...) _hal_debug(HAL_DEBUG_INIT, NULL, args) -#define hal_info(args...) _hal_info(HAL_DEBUG_INIT, NULL, args) - -static bool initialized = false; - -void hal_api_init() -{ - if (!initialized) - hal_debug_init(); - hal_info("%s begin, initialized=%d, debug=0x%02x\n", __FUNCTION__, (int)initialized, debuglevel); - if (!initialized) - { - cCpuFreqManager f; - f.SetCpuFreq(0); /* CPUFREQ == 0 is the trigger for leaving standby */ - char buffer[64]; - sprintf(buffer, "%x", 0); - proc_put("/proc/stb/fb/dst_top", buffer, strlen(buffer)); - proc_put("/proc/stb/fb/dst_left", buffer, strlen(buffer)); - sprintf(buffer, "%x", 576); - proc_put("/proc/stb/fb/dst_height", buffer, strlen(buffer)); - sprintf(buffer, "%x", 720); - proc_put("/proc/stb/fb/dst_width", buffer, strlen(buffer)); - sprintf(buffer, "%x", 1); - proc_put("/proc/stb/fb/dst_apply", buffer, strlen(buffer)); -#if BOXMODEL_VUSOLO4K || BOXMODEL_VUDUO4K || BOXMODEL_VUDUO4KSE || BOXMODEL_VUULTIMO4K || BOXMODEL_VUUNO4KSE || BOXMODEL_VUUNO4K - sprintf(buffer, "%s", "enable"); - proc_put("/proc/stb/frontend/fbc/fcc", buffer, strlen(buffer)); -#endif - } - initialized = true; - hal_info("%s end\n", __FUNCTION__); -} - -void hal_api_exit() -{ - hal_info("%s, initialized = %d\n", __FUNCTION__, (int)initialized); - initialized = false; -} diff --git a/libmipsbox/init.cpp b/libmipsbox/init.cpp new file mode 120000 index 0000000..7de8db4 --- /dev/null +++ b/libmipsbox/init.cpp @@ -0,0 +1 @@ +../libarmbox/init.cpp \ No newline at end of file diff --git a/libmipsbox/linux-uapi-cec.h b/libmipsbox/linux-uapi-cec.h deleted file mode 100644 index 851968e..0000000 --- a/libmipsbox/linux-uapi-cec.h +++ /dev/null @@ -1,1014 +0,0 @@ -/* - * cec - HDMI Consumer Electronics Control public header - * - * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. - * - * This program is free software; you may redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * Alternatively you can redistribute this file under the terms of the - * BSD license as stated below: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. The names of its contributors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * Note: this framework is still in staging and it is likely the API - * will change before it goes out of staging. - * - * Once it is moved out of staging this header will move to uapi. - */ -#ifndef _CEC_UAPI_H -#define _CEC_UAPI_H - -#include - -#define CEC_MAX_MSG_SIZE 16 - -/** - * struct cec_msg - CEC message structure. - * @tx_ts: Timestamp in nanoseconds using CLOCK_MONOTONIC. Set by the - * driver when the message transmission has finished. - * @rx_ts: Timestamp in nanoseconds using CLOCK_MONOTONIC. Set by the - * driver when the message was received. - * @len: Length in bytes of the message. - * @timeout: The timeout (in ms) that is used to timeout CEC_RECEIVE. - * Set to 0 if you want to wait forever. This timeout can also be - * used with CEC_TRANSMIT as the timeout for waiting for a reply. - * If 0, then it will use a 1 second timeout instead of waiting - * forever as is done with CEC_RECEIVE. - * @sequence: The framework assigns a sequence number to messages that are - * sent. This can be used to track replies to previously sent - * messages. - * @flags: Set to 0. - * @msg: The message payload. - * @reply: This field is ignored with CEC_RECEIVE and is only used by - * CEC_TRANSMIT. If non-zero, then wait for a reply with this - * opcode. Set to CEC_MSG_FEATURE_ABORT if you want to wait for - * a possible ABORT reply. If there was an error when sending the - * msg or FeatureAbort was returned, then reply is set to 0. - * If reply is non-zero upon return, then len/msg are set to - * the received message. - * If reply is zero upon return and status has the - * CEC_TX_STATUS_FEATURE_ABORT bit set, then len/msg are set to - * the received feature abort message. - * If reply is zero upon return and status has the - * CEC_TX_STATUS_MAX_RETRIES bit set, then no reply was seen at - * all. If reply is non-zero for CEC_TRANSMIT and the message is a - * broadcast, then -EINVAL is returned. - * if reply is non-zero, then timeout is set to 1000 (the required - * maximum response time). - * @rx_status: The message receive status bits. Set by the driver. - * @tx_status: The message transmit status bits. Set by the driver. - * @tx_arb_lost_cnt: The number of 'Arbitration Lost' events. Set by the driver. - * @tx_nack_cnt: The number of 'Not Acknowledged' events. Set by the driver. - * @tx_low_drive_cnt: The number of 'Low Drive Detected' events. Set by the - * driver. - * @tx_error_cnt: The number of 'Error' events. Set by the driver. - */ -struct cec_msg { - __u64 tx_ts; - __u64 rx_ts; - __u32 len; - __u32 timeout; - __u32 sequence; - __u32 flags; - __u8 msg[CEC_MAX_MSG_SIZE]; - __u8 reply; - __u8 rx_status; - __u8 tx_status; - __u8 tx_arb_lost_cnt; - __u8 tx_nack_cnt; - __u8 tx_low_drive_cnt; - __u8 tx_error_cnt; -}; - -/** - * cec_msg_initiator - return the initiator's logical address. - * @msg: the message structure - */ -static inline __u8 cec_msg_initiator(const struct cec_msg *msg) -{ - return msg->msg[0] >> 4; -} - -/** - * cec_msg_destination - return the destination's logical address. - * @msg: the message structure - */ -static inline __u8 cec_msg_destination(const struct cec_msg *msg) -{ - return msg->msg[0] & 0xf; -} - -/** - * cec_msg_opcode - return the opcode of the message, -1 for poll - * @msg: the message structure - */ -static inline int cec_msg_opcode(const struct cec_msg *msg) -{ - return msg->len > 1 ? msg->msg[1] : -1; -} - -/** - * cec_msg_is_broadcast - return true if this is a broadcast message. - * @msg: the message structure - */ -static inline bool cec_msg_is_broadcast(const struct cec_msg *msg) -{ - return (msg->msg[0] & 0xf) == 0xf; -} - -/** - * cec_msg_init - initialize the message structure. - * @msg: the message structure - * @initiator: the logical address of the initiator - * @destination:the logical address of the destination (0xf for broadcast) - * - * The whole structure is zeroed, the len field is set to 1 (i.e. a poll - * message) and the initiator and destination are filled in. - */ -static inline void cec_msg_init(struct cec_msg *msg, - __u8 initiator, __u8 destination) -{ - memset(msg, 0, sizeof(*msg)); - msg->msg[0] = (initiator << 4) | destination; - msg->len = 1; -} - -/** - * cec_msg_set_reply_to - fill in destination/initiator in a reply message. - * @msg: the message structure for the reply - * @orig: the original message structure - * - * Set the msg destination to the orig initiator and the msg initiator to the - * orig destination. Note that msg and orig may be the same pointer, in which - * case the change is done in place. - */ -static inline void cec_msg_set_reply_to(struct cec_msg *msg, - struct cec_msg *orig) -{ - /* The destination becomes the initiator and vice versa */ - msg->msg[0] = (cec_msg_destination(orig) << 4) | - cec_msg_initiator(orig); - msg->reply = msg->timeout = 0; -} - -/* cec status field */ -#define CEC_TX_STATUS_OK (1 << 0) -#define CEC_TX_STATUS_ARB_LOST (1 << 1) -#define CEC_TX_STATUS_NACK (1 << 2) -#define CEC_TX_STATUS_LOW_DRIVE (1 << 3) -#define CEC_TX_STATUS_ERROR (1 << 4) -#define CEC_TX_STATUS_MAX_RETRIES (1 << 5) - -#define CEC_RX_STATUS_OK (1 << 0) -#define CEC_RX_STATUS_TIMEOUT (1 << 1) -#define CEC_RX_STATUS_FEATURE_ABORT (1 << 2) - -static inline bool cec_msg_status_is_ok(const struct cec_msg *msg) -{ - if (msg->tx_status && !(msg->tx_status & CEC_TX_STATUS_OK)) - return false; - if (msg->rx_status && !(msg->rx_status & CEC_RX_STATUS_OK)) - return false; - if (!msg->tx_status && !msg->rx_status) - return false; - return !(msg->rx_status & CEC_RX_STATUS_FEATURE_ABORT); -} - -#define CEC_LOG_ADDR_INVALID 0xff -#define CEC_PHYS_ADDR_INVALID 0xffff - -/* - * The maximum number of logical addresses one device can be assigned to. - * The CEC 2.0 spec allows for only 2 logical addresses at the moment. The - * Analog Devices CEC hardware supports 3. So let's go wild and go for 4. - */ -#define CEC_MAX_LOG_ADDRS 4 - -/* The logical addresses defined by CEC 2.0 */ -#define CEC_LOG_ADDR_TV 0 -#define CEC_LOG_ADDR_RECORD_1 1 -#define CEC_LOG_ADDR_RECORD_2 2 -#define CEC_LOG_ADDR_TUNER_1 3 -#define CEC_LOG_ADDR_PLAYBACK_1 4 -#define CEC_LOG_ADDR_AUDIOSYSTEM 5 -#define CEC_LOG_ADDR_TUNER_2 6 -#define CEC_LOG_ADDR_TUNER_3 7 -#define CEC_LOG_ADDR_PLAYBACK_2 8 -#define CEC_LOG_ADDR_RECORD_3 9 -#define CEC_LOG_ADDR_TUNER_4 10 -#define CEC_LOG_ADDR_PLAYBACK_3 11 -#define CEC_LOG_ADDR_BACKUP_1 12 -#define CEC_LOG_ADDR_BACKUP_2 13 -#define CEC_LOG_ADDR_SPECIFIC 14 -#define CEC_LOG_ADDR_UNREGISTERED 15 /* as initiator address */ -#define CEC_LOG_ADDR_BROADCAST 15 /* ad destination address */ - -/* The logical address types that the CEC device wants to claim */ -#define CEC_LOG_ADDR_TYPE_TV 0 -#define CEC_LOG_ADDR_TYPE_RECORD 1 -#define CEC_LOG_ADDR_TYPE_TUNER 2 -#define CEC_LOG_ADDR_TYPE_PLAYBACK 3 -#define CEC_LOG_ADDR_TYPE_AUDIOSYSTEM 4 -#define CEC_LOG_ADDR_TYPE_SPECIFIC 5 -#define CEC_LOG_ADDR_TYPE_UNREGISTERED 6 -/* - * Switches should use UNREGISTERED. - * Processors should use SPECIFIC. - */ - -#define CEC_LOG_ADDR_MASK_TV (1 << CEC_LOG_ADDR_TV) -#define CEC_LOG_ADDR_MASK_RECORD ((1 << CEC_LOG_ADDR_RECORD_1) | \ - (1 << CEC_LOG_ADDR_RECORD_2) | \ - (1 << CEC_LOG_ADDR_RECORD_3)) -#define CEC_LOG_ADDR_MASK_TUNER ((1 << CEC_LOG_ADDR_TUNER_1) | \ - (1 << CEC_LOG_ADDR_TUNER_2) | \ - (1 << CEC_LOG_ADDR_TUNER_3) | \ - (1 << CEC_LOG_ADDR_TUNER_4)) -#define CEC_LOG_ADDR_MASK_PLAYBACK ((1 << CEC_LOG_ADDR_PLAYBACK_1) | \ - (1 << CEC_LOG_ADDR_PLAYBACK_2) | \ - (1 << CEC_LOG_ADDR_PLAYBACK_3)) -#define CEC_LOG_ADDR_MASK_AUDIOSYSTEM (1 << CEC_LOG_ADDR_AUDIOSYSTEM) -#define CEC_LOG_ADDR_MASK_BACKUP ((1 << CEC_LOG_ADDR_BACKUP_1) | \ - (1 << CEC_LOG_ADDR_BACKUP_2)) -#define CEC_LOG_ADDR_MASK_SPECIFIC (1 << CEC_LOG_ADDR_SPECIFIC) -#define CEC_LOG_ADDR_MASK_UNREGISTERED (1 << CEC_LOG_ADDR_UNREGISTERED) - -static inline bool cec_has_tv(__u16 log_addr_mask) -{ - return log_addr_mask & CEC_LOG_ADDR_MASK_TV; -} - -static inline bool cec_has_record(__u16 log_addr_mask) -{ - return log_addr_mask & CEC_LOG_ADDR_MASK_RECORD; -} - -static inline bool cec_has_tuner(__u16 log_addr_mask) -{ - return log_addr_mask & CEC_LOG_ADDR_MASK_TUNER; -} - -static inline bool cec_has_playback(__u16 log_addr_mask) -{ - return log_addr_mask & CEC_LOG_ADDR_MASK_PLAYBACK; -} - -static inline bool cec_has_audiosystem(__u16 log_addr_mask) -{ - return log_addr_mask & CEC_LOG_ADDR_MASK_AUDIOSYSTEM; -} - -static inline bool cec_has_backup(__u16 log_addr_mask) -{ - return log_addr_mask & CEC_LOG_ADDR_MASK_BACKUP; -} - -static inline bool cec_has_specific(__u16 log_addr_mask) -{ - return log_addr_mask & CEC_LOG_ADDR_MASK_SPECIFIC; -} - -static inline bool cec_is_unregistered(__u16 log_addr_mask) -{ - return log_addr_mask & CEC_LOG_ADDR_MASK_UNREGISTERED; -} - -static inline bool cec_is_unconfigured(__u16 log_addr_mask) -{ - return log_addr_mask == 0; -} - -/* - * Use this if there is no vendor ID (CEC_G_VENDOR_ID) or if the vendor ID - * should be disabled (CEC_S_VENDOR_ID) - */ -#define CEC_VENDOR_ID_NONE 0xffffffff - -/* The message handling modes */ -/* Modes for initiator */ -#define CEC_MODE_NO_INITIATOR (0x0 << 0) -#define CEC_MODE_INITIATOR (0x1 << 0) -#define CEC_MODE_EXCL_INITIATOR (0x2 << 0) -#define CEC_MODE_INITIATOR_MSK 0x0f - -/* Modes for follower */ -#define CEC_MODE_NO_FOLLOWER (0x0 << 4) -#define CEC_MODE_FOLLOWER (0x1 << 4) -#define CEC_MODE_EXCL_FOLLOWER (0x2 << 4) -#define CEC_MODE_EXCL_FOLLOWER_PASSTHRU (0x3 << 4) -#define CEC_MODE_MONITOR (0xe << 4) -#define CEC_MODE_MONITOR_ALL (0xf << 4) -#define CEC_MODE_FOLLOWER_MSK 0xf0 - -/* Userspace has to configure the physical address */ -#define CEC_CAP_PHYS_ADDR (1 << 0) -/* Userspace has to configure the logical addresses */ -#define CEC_CAP_LOG_ADDRS (1 << 1) -/* Userspace can transmit messages (and thus become follower as well) */ -#define CEC_CAP_TRANSMIT (1 << 2) -/* - * Passthrough all messages instead of processing them. - */ -#define CEC_CAP_PASSTHROUGH (1 << 3) -/* Supports remote control */ -#define CEC_CAP_RC (1 << 4) -/* Hardware can monitor all messages, not just directed and broadcast. */ -#define CEC_CAP_MONITOR_ALL (1 << 5) - -/** - * struct cec_caps - CEC capabilities structure. - * @driver: name of the CEC device driver. - * @name: name of the CEC device. @driver + @name must be unique. - * @available_log_addrs: number of available logical addresses. - * @capabilities: capabilities of the CEC adapter. - * @version: version of the CEC adapter framework. - */ -struct cec_caps { - char driver[32]; - char name[32]; - __u32 available_log_addrs; - __u32 capabilities; - __u32 version; -}; - -/** - * struct cec_log_addrs - CEC logical addresses structure. - * @log_addr: the claimed logical addresses. Set by the driver. - * @log_addr_mask: current logical address mask. Set by the driver. - * @cec_version: the CEC version that the adapter should implement. Set by the - * caller. - * @num_log_addrs: how many logical addresses should be claimed. Set by the - * caller. - * @vendor_id: the vendor ID of the device. Set by the caller. - * @flags: flags. - * @osd_name: the OSD name of the device. Set by the caller. - * @primary_device_type: the primary device type for each logical address. - * Set by the caller. - * @log_addr_type: the logical address types. Set by the caller. - * @all_device_types: CEC 2.0: all device types represented by the logical - * address. Set by the caller. - * @features: CEC 2.0: The logical address features. Set by the caller. - */ -struct cec_log_addrs { - __u8 log_addr[CEC_MAX_LOG_ADDRS]; - __u16 log_addr_mask; - __u8 cec_version; - __u8 num_log_addrs; - __u32 vendor_id; - __u32 flags; - char osd_name[15]; - __u8 primary_device_type[CEC_MAX_LOG_ADDRS]; - __u8 log_addr_type[CEC_MAX_LOG_ADDRS]; - - /* CEC 2.0 */ - __u8 all_device_types[CEC_MAX_LOG_ADDRS]; - __u8 features[CEC_MAX_LOG_ADDRS][12]; -}; - -/* Allow a fallback to unregistered */ -#define CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK (1 << 0) - -/* Events */ - -/* Event that occurs when the adapter state changes */ -#define CEC_EVENT_STATE_CHANGE 1 -/* - * This event is sent when messages are lost because the application - * didn't empty the message queue in time - */ -#define CEC_EVENT_LOST_MSGS 2 - -#define CEC_EVENT_FL_INITIAL_STATE (1 << 0) - -/** - * struct cec_event_state_change - used when the CEC adapter changes state. - * @phys_addr: the current physical address - * @log_addr_mask: the current logical address mask - */ -struct cec_event_state_change { - __u16 phys_addr; - __u16 log_addr_mask; -}; - -/** - * struct cec_event_lost_msgs - tells you how many messages were lost due. - * @lost_msgs: how many messages were lost. - */ -struct cec_event_lost_msgs { - __u32 lost_msgs; -}; - -/** - * struct cec_event - CEC event structure - * @ts: the timestamp of when the event was sent. - * @event: the event. - * array. - * @state_change: the event payload for CEC_EVENT_STATE_CHANGE. - * @lost_msgs: the event payload for CEC_EVENT_LOST_MSGS. - * @raw: array to pad the union. - */ -struct cec_event { - __u64 ts; - __u32 event; - __u32 flags; - union { - struct cec_event_state_change state_change; - struct cec_event_lost_msgs lost_msgs; - __u32 raw[16]; - }; -}; - -/* ioctls */ - -/* Adapter capabilities */ -#define CEC_ADAP_G_CAPS _IOWR('a', 0, struct cec_caps) - -/* - * phys_addr is either 0 (if this is the CEC root device) - * or a valid physical address obtained from the sink's EDID - * as read by this CEC device (if this is a source device) - * or a physical address obtained and modified from a sink - * EDID and used for a sink CEC device. - * If nothing is connected, then phys_addr is 0xffff. - * See HDMI 1.4b, section 8.7 (Physical Address). - * - * The CEC_ADAP_S_PHYS_ADDR ioctl may not be available if that is handled - * internally. - */ -#define CEC_ADAP_G_PHYS_ADDR _IOR('a', 1, __u16) -#define CEC_ADAP_S_PHYS_ADDR _IOW('a', 2, __u16) - -/* - * Configure the CEC adapter. It sets the device type and which - * logical types it will try to claim. It will return which - * logical addresses it could actually claim. - * An error is returned if the adapter is disabled or if there - * is no physical address assigned. - */ - -#define CEC_ADAP_G_LOG_ADDRS _IOR('a', 3, struct cec_log_addrs) -#define CEC_ADAP_S_LOG_ADDRS _IOWR('a', 4, struct cec_log_addrs) - -/* Transmit/receive a CEC command */ -#define CEC_TRANSMIT _IOWR('a', 5, struct cec_msg) -#define CEC_RECEIVE _IOWR('a', 6, struct cec_msg) - -/* Dequeue CEC events */ -#define CEC_DQEVENT _IOWR('a', 7, struct cec_event) - -/* - * Get and set the message handling mode for this filehandle. - */ -#define CEC_G_MODE _IOR('a', 8, __u32) -#define CEC_S_MODE _IOW('a', 9, __u32) - -/* - * The remainder of this header defines all CEC messages and operands. - * The format matters since it the cec-ctl utility parses it to generate - * code for implementing all these messages. - * - * Comments ending with 'Feature' group messages for each feature. - * If messages are part of multiple features, then the "Has also" - * comment is used to list the previously defined messages that are - * supported by the feature. - * - * Before operands are defined a comment is added that gives the - * name of the operand and in brackets the variable name of the - * corresponding argument in the cec-funcs.h function. - */ - -/* Messages */ - -/* One Touch Play Feature */ -#define CEC_MSG_ACTIVE_SOURCE 0x82 -#define CEC_MSG_IMAGE_VIEW_ON 0x04 -#define CEC_MSG_TEXT_VIEW_ON 0x0d - - -/* Routing Control Feature */ - -/* - * Has also: - * CEC_MSG_ACTIVE_SOURCE - */ - -#define CEC_MSG_INACTIVE_SOURCE 0x9d -#define CEC_MSG_REQUEST_ACTIVE_SOURCE 0x85 -#define CEC_MSG_ROUTING_CHANGE 0x80 -#define CEC_MSG_ROUTING_INFORMATION 0x81 -#define CEC_MSG_SET_STREAM_PATH 0x86 - - -/* Standby Feature */ -#define CEC_MSG_STANDBY 0x36 - - -/* One Touch Record Feature */ -#define CEC_MSG_RECORD_OFF 0x0b -#define CEC_MSG_RECORD_ON 0x09 -/* Record Source Type Operand (rec_src_type) */ -#define CEC_OP_RECORD_SRC_OWN 1 -#define CEC_OP_RECORD_SRC_DIGITAL 2 -#define CEC_OP_RECORD_SRC_ANALOG 3 -#define CEC_OP_RECORD_SRC_EXT_PLUG 4 -#define CEC_OP_RECORD_SRC_EXT_PHYS_ADDR 5 -/* Service Identification Method Operand (service_id_method) */ -#define CEC_OP_SERVICE_ID_METHOD_BY_DIG_ID 0 -#define CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL 1 -/* Digital Service Broadcast System Operand (dig_bcast_system) */ -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_GEN 0x00 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_GEN 0x01 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_GEN 0x02 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_BS 0x08 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_CS 0x09 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ARIB_T 0x0a -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_CABLE 0x10 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_SAT 0x11 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_T 0x12 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_C 0x18 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_S 0x19 -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_S2 0x1a -#define CEC_OP_DIG_SERVICE_BCAST_SYSTEM_DVB_T 0x1b -/* Analogue Broadcast Type Operand (ana_bcast_type) */ -#define CEC_OP_ANA_BCAST_TYPE_CABLE 0 -#define CEC_OP_ANA_BCAST_TYPE_SATELLITE 1 -#define CEC_OP_ANA_BCAST_TYPE_TERRESTRIAL 2 -/* Broadcast System Operand (bcast_system) */ -#define CEC_OP_BCAST_SYSTEM_PAL_BG 0x00 -#define CEC_OP_BCAST_SYSTEM_SECAM_LQ 0x01 /* SECAM L' */ -#define CEC_OP_BCAST_SYSTEM_PAL_M 0x02 -#define CEC_OP_BCAST_SYSTEM_NTSC_M 0x03 -#define CEC_OP_BCAST_SYSTEM_PAL_I 0x04 -#define CEC_OP_BCAST_SYSTEM_SECAM_DK 0x05 -#define CEC_OP_BCAST_SYSTEM_SECAM_BG 0x06 -#define CEC_OP_BCAST_SYSTEM_SECAM_L 0x07 -#define CEC_OP_BCAST_SYSTEM_PAL_DK 0x08 -#define CEC_OP_BCAST_SYSTEM_OTHER 0x1f -/* Channel Number Format Operand (channel_number_fmt) */ -#define CEC_OP_CHANNEL_NUMBER_FMT_1_PART 0x01 -#define CEC_OP_CHANNEL_NUMBER_FMT_2_PART 0x02 - -#define CEC_MSG_RECORD_STATUS 0x0a -/* Record Status Operand (rec_status) */ -#define CEC_OP_RECORD_STATUS_CUR_SRC 0x01 -#define CEC_OP_RECORD_STATUS_DIG_SERVICE 0x02 -#define CEC_OP_RECORD_STATUS_ANA_SERVICE 0x03 -#define CEC_OP_RECORD_STATUS_EXT_INPUT 0x04 -#define CEC_OP_RECORD_STATUS_NO_DIG_SERVICE 0x05 -#define CEC_OP_RECORD_STATUS_NO_ANA_SERVICE 0x06 -#define CEC_OP_RECORD_STATUS_NO_SERVICE 0x07 -#define CEC_OP_RECORD_STATUS_INVALID_EXT_PLUG 0x09 -#define CEC_OP_RECORD_STATUS_INVALID_EXT_PHYS_ADDR 0x0a -#define CEC_OP_RECORD_STATUS_UNSUP_CA 0x0b -#define CEC_OP_RECORD_STATUS_NO_CA_ENTITLEMENTS 0x0c -#define CEC_OP_RECORD_STATUS_CANT_COPY_SRC 0x0d -#define CEC_OP_RECORD_STATUS_NO_MORE_COPIES 0x0e -#define CEC_OP_RECORD_STATUS_NO_MEDIA 0x10 -#define CEC_OP_RECORD_STATUS_PLAYING 0x11 -#define CEC_OP_RECORD_STATUS_ALREADY_RECORDING 0x12 -#define CEC_OP_RECORD_STATUS_MEDIA_PROT 0x13 -#define CEC_OP_RECORD_STATUS_NO_SIGNAL 0x14 -#define CEC_OP_RECORD_STATUS_MEDIA_PROBLEM 0x15 -#define CEC_OP_RECORD_STATUS_NO_SPACE 0x16 -#define CEC_OP_RECORD_STATUS_PARENTAL_LOCK 0x17 -#define CEC_OP_RECORD_STATUS_TERMINATED_OK 0x1a -#define CEC_OP_RECORD_STATUS_ALREADY_TERM 0x1b -#define CEC_OP_RECORD_STATUS_OTHER 0x1f - -#define CEC_MSG_RECORD_TV_SCREEN 0x0f - - -/* Timer Programming Feature */ -#define CEC_MSG_CLEAR_ANALOGUE_TIMER 0x33 -/* Recording Sequence Operand (recording_seq) */ -#define CEC_OP_REC_SEQ_SUNDAY 0x01 -#define CEC_OP_REC_SEQ_MONDAY 0x02 -#define CEC_OP_REC_SEQ_TUESDAY 0x04 -#define CEC_OP_REC_SEQ_WEDNESDAY 0x08 -#define CEC_OP_REC_SEQ_THURSDAY 0x10 -#define CEC_OP_REC_SEQ_FRIDAY 0x20 -#define CEC_OP_REC_SEQ_SATERDAY 0x40 -#define CEC_OP_REC_SEQ_ONCE_ONLY 0x00 - -#define CEC_MSG_CLEAR_DIGITAL_TIMER 0x99 - -#define CEC_MSG_CLEAR_EXT_TIMER 0xa1 -/* External Source Specifier Operand (ext_src_spec) */ -#define CEC_OP_EXT_SRC_PLUG 0x04 -#define CEC_OP_EXT_SRC_PHYS_ADDR 0x05 - -#define CEC_MSG_SET_ANALOGUE_TIMER 0x34 -#define CEC_MSG_SET_DIGITAL_TIMER 0x97 -#define CEC_MSG_SET_EXT_TIMER 0xa2 - -#define CEC_MSG_SET_TIMER_PROGRAM_TITLE 0x67 -#define CEC_MSG_TIMER_CLEARED_STATUS 0x43 -/* Timer Cleared Status Data Operand (timer_cleared_status) */ -#define CEC_OP_TIMER_CLR_STAT_RECORDING 0x00 -#define CEC_OP_TIMER_CLR_STAT_NO_MATCHING 0x01 -#define CEC_OP_TIMER_CLR_STAT_NO_INFO 0x02 -#define CEC_OP_TIMER_CLR_STAT_CLEARED 0x80 - -#define CEC_MSG_TIMER_STATUS 0x35 -/* Timer Overlap Warning Operand (timer_overlap_warning) */ -#define CEC_OP_TIMER_OVERLAP_WARNING_NO_OVERLAP 0 -#define CEC_OP_TIMER_OVERLAP_WARNING_OVERLAP 1 -/* Media Info Operand (media_info) */ -#define CEC_OP_MEDIA_INFO_UNPROT_MEDIA 0 -#define CEC_OP_MEDIA_INFO_PROT_MEDIA 1 -#define CEC_OP_MEDIA_INFO_NO_MEDIA 2 -/* Programmed Indicator Operand (prog_indicator) */ -#define CEC_OP_PROG_IND_NOT_PROGRAMMED 0 -#define CEC_OP_PROG_IND_PROGRAMMED 1 -/* Programmed Info Operand (prog_info) */ -#define CEC_OP_PROG_INFO_ENOUGH_SPACE 0x08 -#define CEC_OP_PROG_INFO_NOT_ENOUGH_SPACE 0x09 -#define CEC_OP_PROG_INFO_MIGHT_NOT_BE_ENOUGH_SPACE 0x0b -#define CEC_OP_PROG_INFO_NONE_AVAILABLE 0x0a -/* Not Programmed Error Info Operand (prog_error) */ -#define CEC_OP_PROG_ERROR_NO_FREE_TIMER 0x01 -#define CEC_OP_PROG_ERROR_DATE_OUT_OF_RANGE 0x02 -#define CEC_OP_PROG_ERROR_REC_SEQ_ERROR 0x03 -#define CEC_OP_PROG_ERROR_INV_EXT_PLUG 0x04 -#define CEC_OP_PROG_ERROR_INV_EXT_PHYS_ADDR 0x05 -#define CEC_OP_PROG_ERROR_CA_UNSUPP 0x06 -#define CEC_OP_PROG_ERROR_INSUF_CA_ENTITLEMENTS 0x07 -#define CEC_OP_PROG_ERROR_RESOLUTION_UNSUPP 0x08 -#define CEC_OP_PROG_ERROR_PARENTAL_LOCK 0x09 -#define CEC_OP_PROG_ERROR_CLOCK_FAILURE 0x0a -#define CEC_OP_PROG_ERROR_DUPLICATE 0x0e - - -/* System Information Feature */ -#define CEC_MSG_CEC_VERSION 0x9e -/* CEC Version Operand (cec_version) */ -#define CEC_OP_CEC_VERSION_1_3A 4 -#define CEC_OP_CEC_VERSION_1_4 5 -#define CEC_OP_CEC_VERSION_2_0 6 - -#define CEC_MSG_GET_CEC_VERSION 0x9f -#define CEC_MSG_GIVE_PHYSICAL_ADDR 0x83 -#define CEC_MSG_GET_MENU_LANGUAGE 0x91 -#define CEC_MSG_REPORT_PHYSICAL_ADDR 0x84 -/* Primary Device Type Operand (prim_devtype) */ -#define CEC_OP_PRIM_DEVTYPE_TV 0 -#define CEC_OP_PRIM_DEVTYPE_RECORD 1 -#define CEC_OP_PRIM_DEVTYPE_TUNER 3 -#define CEC_OP_PRIM_DEVTYPE_PLAYBACK 4 -#define CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM 5 -#define CEC_OP_PRIM_DEVTYPE_SWITCH 6 -#define CEC_OP_PRIM_DEVTYPE_PROCESSOR 7 - -#define CEC_MSG_SET_MENU_LANGUAGE 0x32 -#define CEC_MSG_REPORT_FEATURES 0xa6 /* HDMI 2.0 */ -/* All Device Types Operand (all_device_types) */ -#define CEC_OP_ALL_DEVTYPE_TV 0x80 -#define CEC_OP_ALL_DEVTYPE_RECORD 0x40 -#define CEC_OP_ALL_DEVTYPE_TUNER 0x20 -#define CEC_OP_ALL_DEVTYPE_PLAYBACK 0x10 -#define CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM 0x08 -#define CEC_OP_ALL_DEVTYPE_SWITCH 0x04 -/* - * And if you wondering what happened to PROCESSOR devices: those should - * be mapped to a SWITCH. - */ - -/* Valid for RC Profile and Device Feature operands */ -#define CEC_OP_FEAT_EXT 0x80 /* Extension bit */ -/* RC Profile Operand (rc_profile) */ -#define CEC_OP_FEAT_RC_TV_PROFILE_NONE 0x00 -#define CEC_OP_FEAT_RC_TV_PROFILE_1 0x02 -#define CEC_OP_FEAT_RC_TV_PROFILE_2 0x06 -#define CEC_OP_FEAT_RC_TV_PROFILE_3 0x0a -#define CEC_OP_FEAT_RC_TV_PROFILE_4 0x0e -#define CEC_OP_FEAT_RC_SRC_HAS_DEV_ROOT_MENU 0x50 -#define CEC_OP_FEAT_RC_SRC_HAS_DEV_SETUP_MENU 0x48 -#define CEC_OP_FEAT_RC_SRC_HAS_CONTENTS_MENU 0x44 -#define CEC_OP_FEAT_RC_SRC_HAS_MEDIA_TOP_MENU 0x42 -#define CEC_OP_FEAT_RC_SRC_HAS_MEDIA_CONTEXT_MENU 0x41 -/* Device Feature Operand (dev_features) */ -#define CEC_OP_FEAT_DEV_HAS_RECORD_TV_SCREEN 0x40 -#define CEC_OP_FEAT_DEV_HAS_SET_OSD_STRING 0x20 -#define CEC_OP_FEAT_DEV_HAS_DECK_CONTROL 0x10 -#define CEC_OP_FEAT_DEV_HAS_SET_AUDIO_RATE 0x08 -#define CEC_OP_FEAT_DEV_SINK_HAS_ARC_TX 0x04 -#define CEC_OP_FEAT_DEV_SOURCE_HAS_ARC_RX 0x02 - -#define CEC_MSG_GIVE_FEATURES 0xa5 /* HDMI 2.0 */ - - -/* Deck Control Feature */ -#define CEC_MSG_DECK_CONTROL 0x42 -/* Deck Control Mode Operand (deck_control_mode) */ -#define CEC_OP_DECK_CTL_MODE_SKIP_FWD 1 -#define CEC_OP_DECK_CTL_MODE_SKIP_REV 2 -#define CEC_OP_DECK_CTL_MODE_STOP 3 -#define CEC_OP_DECK_CTL_MODE_EJECT 4 - -#define CEC_MSG_DECK_STATUS 0x1b -/* Deck Info Operand (deck_info) */ -#define CEC_OP_DECK_INFO_PLAY 0x11 -#define CEC_OP_DECK_INFO_RECORD 0x12 -#define CEC_OP_DECK_INFO_PLAY_REV 0x13 -#define CEC_OP_DECK_INFO_STILL 0x14 -#define CEC_OP_DECK_INFO_SLOW 0x15 -#define CEC_OP_DECK_INFO_SLOW_REV 0x16 -#define CEC_OP_DECK_INFO_FAST_FWD 0x17 -#define CEC_OP_DECK_INFO_FAST_REV 0x18 -#define CEC_OP_DECK_INFO_NO_MEDIA 0x19 -#define CEC_OP_DECK_INFO_STOP 0x1a -#define CEC_OP_DECK_INFO_SKIP_FWD 0x1b -#define CEC_OP_DECK_INFO_SKIP_REV 0x1c -#define CEC_OP_DECK_INFO_INDEX_SEARCH_FWD 0x1d -#define CEC_OP_DECK_INFO_INDEX_SEARCH_REV 0x1e -#define CEC_OP_DECK_INFO_OTHER 0x1f - -#define CEC_MSG_GIVE_DECK_STATUS 0x1a -/* Status Request Operand (status_req) */ -#define CEC_OP_STATUS_REQ_ON 1 -#define CEC_OP_STATUS_REQ_OFF 2 -#define CEC_OP_STATUS_REQ_ONCE 3 - -#define CEC_MSG_PLAY 0x41 -/* Play Mode Operand (play_mode) */ -#define CEC_OP_PLAY_MODE_PLAY_FWD 0x24 -#define CEC_OP_PLAY_MODE_PLAY_REV 0x20 -#define CEC_OP_PLAY_MODE_PLAY_STILL 0x25 -#define CEC_OP_PLAY_MODE_PLAY_FAST_FWD_MIN 0x05 -#define CEC_OP_PLAY_MODE_PLAY_FAST_FWD_MED 0x06 -#define CEC_OP_PLAY_MODE_PLAY_FAST_FWD_MAX 0x07 -#define CEC_OP_PLAY_MODE_PLAY_FAST_REV_MIN 0x09 -#define CEC_OP_PLAY_MODE_PLAY_FAST_REV_MED 0x0a -#define CEC_OP_PLAY_MODE_PLAY_FAST_REV_MAX 0x0b -#define CEC_OP_PLAY_MODE_PLAY_SLOW_FWD_MIN 0x15 -#define CEC_OP_PLAY_MODE_PLAY_SLOW_FWD_MED 0x16 -#define CEC_OP_PLAY_MODE_PLAY_SLOW_FWD_MAX 0x17 -#define CEC_OP_PLAY_MODE_PLAY_SLOW_REV_MIN 0x19 -#define CEC_OP_PLAY_MODE_PLAY_SLOW_REV_MED 0x1a -#define CEC_OP_PLAY_MODE_PLAY_SLOW_REV_MAX 0x1b - - -/* Tuner Control Feature */ -#define CEC_MSG_GIVE_TUNER_DEVICE_STATUS 0x08 -#define CEC_MSG_SELECT_ANALOGUE_SERVICE 0x92 -#define CEC_MSG_SELECT_DIGITAL_SERVICE 0x93 -#define CEC_MSG_TUNER_DEVICE_STATUS 0x07 -/* Recording Flag Operand (rec_flag) */ -#define CEC_OP_REC_FLAG_USED 0 -#define CEC_OP_REC_FLAG_NOT_USED 1 -/* Tuner Display Info Operand (tuner_display_info) */ -#define CEC_OP_TUNER_DISPLAY_INFO_DIGITAL 0 -#define CEC_OP_TUNER_DISPLAY_INFO_NONE 1 -#define CEC_OP_TUNER_DISPLAY_INFO_ANALOGUE 2 - -#define CEC_MSG_TUNER_STEP_DECREMENT 0x06 -#define CEC_MSG_TUNER_STEP_INCREMENT 0x05 - - -/* Vendor Specific Commands Feature */ - -/* - * Has also: - * CEC_MSG_CEC_VERSION - * CEC_MSG_GET_CEC_VERSION - */ -#define CEC_MSG_DEVICE_VENDOR_ID 0x87 -#define CEC_MSG_GIVE_DEVICE_VENDOR_ID 0x8c -#define CEC_MSG_VENDOR_COMMAND 0x89 -#define CEC_MSG_VENDOR_COMMAND_WITH_ID 0xa0 -#define CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN 0x8a -#define CEC_MSG_VENDOR_REMOTE_BUTTON_UP 0x8b - - -/* OSD Display Feature */ -#define CEC_MSG_SET_OSD_STRING 0x64 -/* Display Control Operand (disp_ctl) */ -#define CEC_OP_DISP_CTL_DEFAULT 0x00 -#define CEC_OP_DISP_CTL_UNTIL_CLEARED 0x40 -#define CEC_OP_DISP_CTL_CLEAR 0x80 - - -/* Device OSD Transfer Feature */ -#define CEC_MSG_GIVE_OSD_NAME 0x46 -#define CEC_MSG_SET_OSD_NAME 0x47 - - -/* Device Menu Control Feature */ -#define CEC_MSG_MENU_REQUEST 0x8d -/* Menu Request Type Operand (menu_req) */ -#define CEC_OP_MENU_REQUEST_ACTIVATE 0x00 -#define CEC_OP_MENU_REQUEST_DEACTIVATE 0x01 -#define CEC_OP_MENU_REQUEST_QUERY 0x02 - -#define CEC_MSG_MENU_STATUS 0x8e -/* Menu State Operand (menu_state) */ -#define CEC_OP_MENU_STATE_ACTIVATED 0x00 -#define CEC_OP_MENU_STATE_DEACTIVATED 0x01 - -#define CEC_MSG_USER_CONTROL_PRESSED 0x44 -/* UI Broadcast Type Operand (ui_bcast_type) */ -#define CEC_OP_UI_BCAST_TYPE_TOGGLE_ALL 0x00 -#define CEC_OP_UI_BCAST_TYPE_TOGGLE_DIG_ANA 0x01 -#define CEC_OP_UI_BCAST_TYPE_ANALOGUE 0x10 -#define CEC_OP_UI_BCAST_TYPE_ANALOGUE_T 0x20 -#define CEC_OP_UI_BCAST_TYPE_ANALOGUE_CABLE 0x30 -#define CEC_OP_UI_BCAST_TYPE_ANALOGUE_SAT 0x40 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL 0x50 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_T 0x60 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_CABLE 0x70 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_SAT 0x80 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_COM_SAT 0x90 -#define CEC_OP_UI_BCAST_TYPE_DIGITAL_COM_SAT2 0x91 -#define CEC_OP_UI_BCAST_TYPE_IP 0xa0 -/* UI Sound Presentation Control Operand (ui_snd_pres_ctl) */ -#define CEC_OP_UI_SND_PRES_CTL_DUAL_MONO 0x10 -#define CEC_OP_UI_SND_PRES_CTL_KARAOKE 0x20 -#define CEC_OP_UI_SND_PRES_CTL_DOWNMIX 0x80 -#define CEC_OP_UI_SND_PRES_CTL_REVERB 0x90 -#define CEC_OP_UI_SND_PRES_CTL_EQUALIZER 0xa0 -#define CEC_OP_UI_SND_PRES_CTL_BASS_UP 0xb1 -#define CEC_OP_UI_SND_PRES_CTL_BASS_NEUTRAL 0xb2 -#define CEC_OP_UI_SND_PRES_CTL_BASS_DOWN 0xb3 -#define CEC_OP_UI_SND_PRES_CTL_TREBLE_UP 0xc1 -#define CEC_OP_UI_SND_PRES_CTL_TREBLE_NEUTRAL 0xc2 -#define CEC_OP_UI_SND_PRES_CTL_TREBLE_DOWN 0xc3 - -#define CEC_MSG_USER_CONTROL_RELEASED 0x45 - - -/* Remote Control Passthrough Feature */ - -/* - * Has also: - * CEC_MSG_USER_CONTROL_PRESSED - * CEC_MSG_USER_CONTROL_RELEASED - */ - - -/* Power Status Feature */ -#define CEC_MSG_GIVE_DEVICE_POWER_STATUS 0x8f -#define CEC_MSG_REPORT_POWER_STATUS 0x90 -/* Power Status Operand (pwr_state) */ -#define CEC_OP_POWER_STATUS_ON 0 -#define CEC_OP_POWER_STATUS_STANDBY 1 -#define CEC_OP_POWER_STATUS_TO_ON 2 -#define CEC_OP_POWER_STATUS_TO_STANDBY 3 - - -/* General Protocol Messages */ -#define CEC_MSG_FEATURE_ABORT 0x00 -/* Abort Reason Operand (reason) */ -#define CEC_OP_ABORT_UNRECOGNIZED_OP 0 -#define CEC_OP_ABORT_INCORRECT_MODE 1 -#define CEC_OP_ABORT_NO_SOURCE 2 -#define CEC_OP_ABORT_INVALID_OP 3 -#define CEC_OP_ABORT_REFUSED 4 -#define CEC_OP_ABORT_UNDETERMINED 5 - -#define CEC_MSG_ABORT 0xff - - -/* System Audio Control Feature */ - -/* - * Has also: - * CEC_MSG_USER_CONTROL_PRESSED - * CEC_MSG_USER_CONTROL_RELEASED - */ -#define CEC_MSG_GIVE_AUDIO_STATUS 0x71 -#define CEC_MSG_GIVE_SYSTEM_AUDIO_MODE_STATUS 0x7d -#define CEC_MSG_REPORT_AUDIO_STATUS 0x7a -/* Audio Mute Status Operand (aud_mute_status) */ -#define CEC_OP_AUD_MUTE_STATUS_OFF 0 -#define CEC_OP_AUD_MUTE_STATUS_ON 1 - -#define CEC_MSG_REPORT_SHORT_AUDIO_DESCRIPTOR 0xa3 -#define CEC_MSG_REQUEST_SHORT_AUDIO_DESCRIPTOR 0xa4 -#define CEC_MSG_SET_SYSTEM_AUDIO_MODE 0x72 -/* System Audio Status Operand (sys_aud_status) */ -#define CEC_OP_SYS_AUD_STATUS_OFF 0 -#define CEC_OP_SYS_AUD_STATUS_ON 1 - -#define CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST 0x70 -#define CEC_MSG_SYSTEM_AUDIO_MODE_STATUS 0x7e -/* Audio Format ID Operand (audio_format_id) */ -#define CEC_OP_AUD_FMT_ID_CEA861 0 -#define CEC_OP_AUD_FMT_ID_CEA861_CXT 1 - - -/* Audio Rate Control Feature */ -#define CEC_MSG_SET_AUDIO_RATE 0x9a -/* Audio Rate Operand (audio_rate) */ -#define CEC_OP_AUD_RATE_OFF 0 -#define CEC_OP_AUD_RATE_WIDE_STD 1 -#define CEC_OP_AUD_RATE_WIDE_FAST 2 -#define CEC_OP_AUD_RATE_WIDE_SLOW 3 -#define CEC_OP_AUD_RATE_NARROW_STD 4 -#define CEC_OP_AUD_RATE_NARROW_FAST 5 -#define CEC_OP_AUD_RATE_NARROW_SLOW 6 - - -/* Audio Return Channel Control Feature */ -#define CEC_MSG_INITIATE_ARC 0xc0 -#define CEC_MSG_REPORT_ARC_INITIATED 0xc1 -#define CEC_MSG_REPORT_ARC_TERMINATED 0xc2 -#define CEC_MSG_REQUEST_ARC_INITIATION 0xc3 -#define CEC_MSG_REQUEST_ARC_TERMINATION 0xc4 -#define CEC_MSG_TERMINATE_ARC 0xc5 - - -/* Dynamic Audio Lipsync Feature */ -/* Only for CEC 2.0 and up */ -#define CEC_MSG_REQUEST_CURRENT_LATENCY 0xa7 -#define CEC_MSG_REPORT_CURRENT_LATENCY 0xa8 -/* Low Latency Mode Operand (low_latency_mode) */ -#define CEC_OP_LOW_LATENCY_MODE_OFF 0 -#define CEC_OP_LOW_LATENCY_MODE_ON 1 -/* Audio Output Compensated Operand (audio_out_compensated) */ -#define CEC_OP_AUD_OUT_COMPENSATED_NA 0 -#define CEC_OP_AUD_OUT_COMPENSATED_DELAY 1 -#define CEC_OP_AUD_OUT_COMPENSATED_NO_DELAY 2 -#define CEC_OP_AUD_OUT_COMPENSATED_PARTIAL_DELAY 3 - - -/* Capability Discovery and Control Feature */ -#define CEC_MSG_CDC_MESSAGE 0xf8 -/* Ethernet-over-HDMI: nobody ever does this... */ -#define CEC_MSG_CDC_HEC_INQUIRE_STATE 0x00 -#define CEC_MSG_CDC_HEC_REPORT_STATE 0x01 -/* HEC Functionality State Operand (hec_func_state) */ -#define CEC_OP_HEC_FUNC_STATE_NOT_SUPPORTED 0 -#define CEC_OP_HEC_FUNC_STATE_INACTIVE 1 -#define CEC_OP_HEC_FUNC_STATE_ACTIVE 2 -#define CEC_OP_HEC_FUNC_STATE_ACTIVATION_FIELD 3 -/* Host Functionality State Operand (host_func_state) */ -#define CEC_OP_HOST_FUNC_STATE_NOT_SUPPORTED 0 -#define CEC_OP_HOST_FUNC_STATE_INACTIVE 1 -#define CEC_OP_HOST_FUNC_STATE_ACTIVE 2 -/* ENC Functionality State Operand (enc_func_state) */ -#define CEC_OP_ENC_FUNC_STATE_EXT_CON_NOT_SUPPORTED 0 -#define CEC_OP_ENC_FUNC_STATE_EXT_CON_INACTIVE 1 -#define CEC_OP_ENC_FUNC_STATE_EXT_CON_ACTIVE 2 -/* CDC Error Code Operand (cdc_errcode) */ -#define CEC_OP_CDC_ERROR_CODE_NONE 0 -#define CEC_OP_CDC_ERROR_CODE_CAP_UNSUPPORTED 1 -#define CEC_OP_CDC_ERROR_CODE_WRONG_STATE 2 -#define CEC_OP_CDC_ERROR_CODE_OTHER 3 -/* HEC Support Operand (hec_support) */ -#define CEC_OP_HEC_SUPPORT_NO 0 -#define CEC_OP_HEC_SUPPORT_YES 1 -/* HEC Activation Operand (hec_activation) */ -#define CEC_OP_HEC_ACTIVATION_ON 0 -#define CEC_OP_HEC_ACTIVATION_OFF 1 - -#define CEC_MSG_CDC_HEC_SET_STATE_ADJACENT 0x02 -#define CEC_MSG_CDC_HEC_SET_STATE 0x03 -/* HEC Set State Operand (hec_set_state) */ -#define CEC_OP_HEC_SET_STATE_DEACTIVATE 0 -#define CEC_OP_HEC_SET_STATE_ACTIVATE 1 - -#define CEC_MSG_CDC_HEC_REQUEST_DEACTIVATION 0x04 -#define CEC_MSG_CDC_HEC_NOTIFY_ALIVE 0x05 -#define CEC_MSG_CDC_HEC_DISCOVER 0x06 -/* Hotplug Detect messages */ -#define CEC_MSG_CDC_HPD_SET_STATE 0x10 -/* HPD State Operand (hpd_state) */ -#define CEC_OP_HPD_STATE_CP_EDID_DISABLE 0 -#define CEC_OP_HPD_STATE_CP_EDID_ENABLE 1 -#define CEC_OP_HPD_STATE_CP_EDID_DISABLE_ENABLE 2 -#define CEC_OP_HPD_STATE_EDID_DISABLE 3 -#define CEC_OP_HPD_STATE_EDID_ENABLE 4 -#define CEC_OP_HPD_STATE_EDID_DISABLE_ENABLE 5 -#define CEC_MSG_CDC_HPD_REPORT_STATE 0x11 -/* HPD Error Code Operand (hpd_error) */ -#define CEC_OP_HPD_ERROR_NONE 0 -#define CEC_OP_HPD_ERROR_INITIATOR_NOT_CAPABLE 1 -#define CEC_OP_HPD_ERROR_INITIATOR_WRONG_STATE 2 -#define CEC_OP_HPD_ERROR_OTHER 3 -#define CEC_OP_HPD_ERROR_NONE_NO_VIDEO 4 - -#endif diff --git a/libmipsbox/linux-uapi-cec.h b/libmipsbox/linux-uapi-cec.h new file mode 120000 index 0000000..993e23b --- /dev/null +++ b/libmipsbox/linux-uapi-cec.h @@ -0,0 +1 @@ +../libarmbox/linux-uapi-cec.h \ No newline at end of file diff --git a/libmipsbox/playback_libeplayer3.cpp b/libmipsbox/playback_libeplayer3.cpp deleted file mode 100644 index 3723b3a..0000000 --- a/libmipsbox/playback_libeplayer3.cpp +++ /dev/null @@ -1,880 +0,0 @@ -#define __USE_FILE_OFFSET64 1 -#include -#include -#include -#include -#include -#include - -#include -#include - -extern "C" { -#include -extern OutputHandler_t OutputHandler; -extern PlaybackHandler_t PlaybackHandler; -extern ContainerHandler_t ContainerHandler; -extern ManagerHandler_t ManagerHandler; -extern int32_t ffmpeg_av_dict_set( const char *key, const char *value, int32_t flags); -} - -#include "playback_libeplayer3.h" -#include "hal_debug.h" - -#define hal_debug(args...) _hal_debug(HAL_DEBUG_PLAYBACK, this, args) -#define hal_info(args...) _hal_info(HAL_DEBUG_PLAYBACK, this, args) - -static Context_t *player = NULL; - -extern cAudio *audioDecoder; -extern cVideo *videoDecoder; -OpenThreads::Mutex cPlayback::mutex; - -//Used by Fileplay -bool cPlayback::Open(playmode_t PlayMode) -{ - const char *aPLAYMODE[] = - { - "PLAYMODE_TS", - "PLAYMODE_FILE" - }; - - if (PlayMode != PLAYMODE_TS) - { - audioDecoder->closeDevice(); - videoDecoder->closeDevice(); - decoders_closed = true; - } - - pm = PlayMode; - got_vpts_ts = false; - vpts_ts = 0; - fn_ts = ""; - fn_xml = ""; - last_size = 0; - nPlaybackSpeed = 0; - init_jump = -1; - avft = avformat_alloc_context(); - - if (!player) - { - player = (Context_t *) malloc(sizeof(Context_t)); - } - - if (player) - { - player->playback = &PlaybackHandler; - player->output = &OutputHandler; - player->container = &ContainerHandler; - player->manager = &ManagerHandler; - - hal_info("%s - player output name: %s PlayMode: %s\n", __func__, player->output->Name, aPLAYMODE[PlayMode]); - } - - //Registration of output devices - if (player && player->output) - { - player->output->Command(player, OUTPUT_ADD, (void *)"audio"); - player->output->Command(player, OUTPUT_ADD, (void *)"video"); - player->output->Command(player, OUTPUT_ADD, (void *)"subtitle"); - } - - return 0; -} - -void cPlayback::Close(void) -{ - hal_info("%s\n", __func__); - - //Dagobert: movieplayer does not call stop, it calls close ;) - mutex.lock(); - if(playing) - Stop(); - mutex.unlock(); - - if (decoders_closed) - { - audioDecoder->openDevice(); - videoDecoder->openDevice(); - decoders_closed = false; - } -} - -bool cPlayback::Start(std::string filename, std::string headers, std::string filename2) -{ - return Start((char *) filename.c_str(), 0, 0, 0, 0, 0, headers,filename2); -} - -bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, int, std::string headers, std::string filename2) -{ - bool ret = false; - bool isHTTP = false; - no_probe = false; - - hal_info("%s - filename=%s vpid=%u vtype=%d apid=%u ac3=%d\n", __func__, filename, vpid, vtype, apid, ac3); - - init_jump = -1; - //create playback path - mAudioStream = 0; - mSubtitleStream = -1; - mTeletextStream = -1; - std::string file; - - if (*filename == '/') - file = "file://"; - file += filename; - - if ((file.find(":31339/id=") != std::string::npos) || (file.find(":10000") != std::string::npos) || (file.find(":8001/") != std::string::npos)) // for LocalTV and Entertain-TV streaming - no_probe = true; - - if (file.substr(0, 7) == "file://") - { - if (file.substr(file.length() - 3) == ".ts") - { - fn_ts = file.substr(7); - fn_xml = file.substr(7, file.length() - 9); - fn_xml += "xml"; - no_probe = true; - } - } - else - isHTTP = true; - - if(isHTTP && headers.empty()) - { - size_t pos = file.find('#'); - if (pos != std::string::npos) - { - headers = file.substr(pos + 1); - pos = headers.find("User-Agent="); - if (pos != std::string::npos) - headers.replace(pos+10, 1, ": "); - } - } - if(!headers.empty()){ - const char hkey[] = "headers"; - ffmpeg_av_dict_set(hkey, headers.c_str(), 0); - } - - std::string szSecondFile; - char *file2 = NULL; - if(!filename2.empty()){ - szSecondFile = filename2; - file2 = (char *) szSecondFile.c_str(); - } - - PlayFiles_t playbackFiles = { (char *) file.c_str(), file2, NULL, NULL, 0, 0, 0, 0}; - if (player->playback->Command(player, PLAYBACK_OPEN, &playbackFiles) == 0) - { - if (pm == PLAYMODE_TS) - { - struct stat64 s; - if (!stat64(file.c_str(), &s)) - last_size = s.st_size; - ret = true; - videoDecoder->Stop(false); - audioDecoder->Stop(); - } - else - { - //AUDIO - if (player && player->manager && player->manager->audio) - { - char ** TrackList = NULL; - player->manager->audio->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("AudioTrack List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i += 2) - { - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - } - } - - //SUB - if (player && player->manager && player->manager->subtitle) - { - char ** TrackList = NULL; - player->manager->subtitle->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("SubtitleTrack List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i+=2) - { - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - } - } - - /* - //Teletext - if (player && player->manager && player->manager->teletext) - { - char ** TrackList = NULL; - player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("TeletextTrack List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i += 2) - { - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - } - } - - */ - //Chapters - if (player && player->manager && player->manager->chapter) - { - char ** TrackList = NULL; - player->manager->chapter->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("Chapter List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i += 2) - { - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - } - } - - playing = true; - first = true; - player->output->Command(player, OUTPUT_OPEN, NULL); - ret = (player->playback->Command(player, PLAYBACK_PLAY, NULL) == 0); - - if (ret && !isHTTP) - playing = ret = (player->playback->Command(player, PLAYBACK_PAUSE, NULL) == 0); - } - } - return ret; -} - -bool cPlayback::Stop(void) -{ - hal_info("%s playing %d\n", __func__, playing); - - if (player && player->playback) - player->playback->Command(player, PLAYBACK_STOP, NULL); - - if (player && player->output) - player->output->Command(player, OUTPUT_CLOSE, NULL); - - if (player && player->output) - { - player->output->Command(player, OUTPUT_DEL, (void *)"audio"); - player->output->Command(player, OUTPUT_DEL, (void *)"video"); - player->output->Command(player, OUTPUT_DEL, (void *)"subtitle"); - } - - if (player && player->playback) - player->playback->Command(player, PLAYBACK_CLOSE, NULL); - - playing = false; - return true; -} - -bool cPlayback::SetAPid(int pid, bool /* ac3 */) -{ - hal_info("%s\n", __func__); - int i = pid; - - if (pid != mAudioStream) - { - if (player && player->playback) - player->playback->Command(player, PLAYBACK_SWITCH_AUDIO, (void *)&i); - mAudioStream = pid; - } - return true; -} - -bool cPlayback::SetVPid(int /*pid*/) -{ - hal_info("%s\n", __func__); - return true; -} - -bool cPlayback::SetSubtitlePid(int pid) -{ - hal_info("%s\n", __func__); - int i = pid; - - if (pid != mSubtitleStream) - { - if (player && player->playback) - player->playback->Command(player, PLAYBACK_SWITCH_SUBTITLE, (void *)&i); - mSubtitleStream = pid; - } - return true; -} - -bool cPlayback::SetTeletextPid(int pid) -{ - hal_info("%s\n", __func__); - - //int i = pid; - - if (pid != mTeletextStream) - { - //if (player && player->playback) - // player->playback->Command(player, PLAYBACK_SWITCH_TELETEXT, (void*)&i); - mTeletextStream = pid; - } - return true; -} - -bool cPlayback::SetSpeed(int speed) -{ - hal_info("%s playing %d speed %d\n", __func__, playing, speed); - - if (!decoders_closed) - { - audioDecoder->closeDevice(); - videoDecoder->closeDevice(); - decoders_closed = true; - usleep(500000); - if (player && player->output && player->playback) - { - player->output->Command(player, OUTPUT_OPEN, NULL); - if (player->playback->Command(player, PLAYBACK_PLAY, NULL) == 0) - playing = true; - } - } - - if (!playing) - return false; - - if (player && player->playback) - { - int result = 0; - if(nPlaybackSpeed == 0 && speed > 1) - { - result = player->playback->Command(player, PLAYBACK_CONTINUE, NULL); - } - - nPlaybackSpeed = speed; - - if (speed > 1) - { - /* direction switch ? */ - if (player->playback->BackWard) - { - int r = 0; - result = player->playback->Command(player, PLAYBACK_FASTBACKWARD, (void *)&r); - printf("result = %d\n", result); - } - result = player->playback->Command(player, PLAYBACK_FASTFORWARD, (void *)&speed); - } - else if (speed < 0) - { - /* direction switch ? */ - if (player->playback->isForwarding) - { - result = player->playback->Command(player, PLAYBACK_CONTINUE, NULL); - printf("result = %d\n", result); - } - result = player->playback->Command(player, PLAYBACK_FASTBACKWARD, (void *)&speed); - } - else if (speed == 0) - { - /* konfetti: hmmm accessing the member isn't very proper */ - if ((player->playback->isForwarding) || (!player->playback->BackWard)) - player->playback->Command(player, PLAYBACK_PAUSE, NULL); - else - { - int _speed = 0; /* means end of reverse playback */ - player->playback->Command(player, PLAYBACK_FASTBACKWARD, (void *)&_speed); - } - } - else - { - result = player->playback->Command(player, PLAYBACK_CONTINUE, NULL); - } - - if (init_jump > -1) - { - SetPosition(init_jump, true); - init_jump = -1; - } - - if (result != 0) - { - printf("returning false\n"); - return false; - } - } - return true; -} - -bool cPlayback::GetSpeed(int &speed) const -{ - hal_debug("%s\n", __func__); - speed = nPlaybackSpeed; - return true; -} - -void cPlayback::GetPts(uint64_t &pts) -{ - if (player && player->playback) - player->playback->Command(player, PLAYBACK_PTS, (void *)&pts); -} - -// in milliseconds -bool cPlayback::GetPosition(int &position, int &duration) -{ - bool got_duration = false; - hal_debug("%s %d %d\n", __func__, position, duration); - - /* hack: if the file is growing (timeshift), then determine its length - * by comparing the mtime with the mtime of the xml file */ - if (pm == PLAYMODE_TS) - { - struct stat64 s; - if (!stat64(fn_ts.c_str(), &s)) - { - if (!playing || last_size != s.st_size) - { - last_size = s.st_size; - time_t curr_time = s.st_mtime; - if (!stat64(fn_xml.c_str(), &s)) - { - duration = (curr_time - s.st_mtime) * 1000; - if (!playing) - return true; - got_duration = true; - } - } - } - } - - if (!playing) - return false; - - if (player && player->playback && !player->playback->isPlaying) - { - hal_info("%s !!!!EOF!!!! < -1\n", __func__); - position = duration + 1000; - return false; - } - - int64_t vpts = 0; - if (player && player->playback) - player->playback->Command(player, PLAYBACK_PTS, &vpts); - - if (vpts <= 0) - { - //printf("ERROR: vpts==0"); - } - else - { - /* workaround for crazy vpts value during timeshift */ - if (!got_vpts_ts && pm == PLAYMODE_TS) - { - vpts_ts = vpts; - got_vpts_ts = true; - } - if (got_vpts_ts) - vpts -= vpts_ts; - /* end workaround */ - /* len is in nanoseconds. we have 90 000 pts per second. */ - position = vpts / 90; - } - - if (got_duration) - return true; - - int64_t length = 0; - - if (player && player->playback) - player->playback->Command(player, PLAYBACK_LENGTH, &length); - - if (length <= 0) - { - duration = duration + 1000; - } - else - { - duration = length * 1000; - } - - return true; -} - -bool cPlayback::SetPosition(int position, bool absolute) -{ - hal_info("%s %d\n", __func__, position); - - if (playing && first) - { - /* the calling sequence is: - * Start() - paused - * SetPosition() - which fails if not running - * SetSpeed() - to start playing - * so let's remember the initial jump position and later jump to it - */ - init_jump = position; - first = false; - return false; - } - - int64_t pos = (position / 1000.0); - - if (player && player->playback) - player->playback->Command(player, absolute ? PLAYBACK_SEEK_ABS : PLAYBACK_SEEK, (void *)&pos); - - return true; -} - -void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language) -{ - hal_info("%s\n", __func__); - int max_numpida = *numpida; - *numpida = 0; - - if (player && player->playback && player->playback->isPlaying && player->manager && player->manager->audio) - { - char **TrackList = NULL; - player->manager->audio->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("AudioTrack List\n"); - int i = 0, j = 0; - for (i = 0, j = 0; TrackList[i] != NULL; i += 2, j++) - { - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - if (j < max_numpida) - { - int _pid = 0; - std::string _lang ; - std::istringstream iss(TrackList[i]) ; - iss >> _pid; - iss >> _lang; - if (_pid && !_lang.empty()) - { - apids[j] = _pid; - // atUnknown, atMPEG, atMP3, atAC3, atDTS, atAAC, atPCM, atOGG, atFLAC - if (!strncmp("A_MPEG/L3", TrackList[i + 1], 9)) - ac3flags[j] = 3; - if (!strncmp("A_MP3", TrackList[i + 1], 5)) - ac3flags[j] = 4; - else if (!strncmp("A_AC3", TrackList[i + 1], 5)) - ac3flags[j] = 1; - else if (!strncmp("A_EAC3", TrackList[i + 1], 6)) - ac3flags[j] = 7; - else if (!strncmp("A_DTS", TrackList[i + 1], 5)) - ac3flags[j] = 6; - else if (!strncmp("A_AAC", TrackList[i + 1], 5)) - ac3flags[j] = 5; - else if (!strncmp("A_PCM", TrackList[i + 1], 5)) - ac3flags[j] = 0; //todo - else if (!strncmp("A_VORBIS", TrackList[i + 1], 8)) - ac3flags[j] = 0; //todo - else if (!strncmp("A_FLAC", TrackList[i + 1], 6)) - ac3flags[j] = 0; //todo - else - ac3flags[j] = 0; //todo - std::string _language = ""; - _language += _lang; - _language += " - "; - _language += "("; - _language += TrackList[i + 1]; - _language += ")"; - language[j] = _language; - } - } - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - *numpida = j; - } - } -} - -void cPlayback::FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language) -{ - hal_info("%s\n", __func__); - - int max_numpids = *numpids; - *numpids = 0; - - if (player && player->manager && player->manager->subtitle) - { - char **TrackList = NULL; - player->manager->subtitle->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("SubtitleTrack List\n"); - int i = 0, j = 0; - for (i = 0, j = 0; TrackList[i] != NULL; i += 2, j++) - { - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - if (j < max_numpids) - { - int _pid = 0; - std::string _lang ; - std::istringstream iss(TrackList[i]) ; - iss >> _pid; - iss >> _lang; - if (_pid && !_lang.empty()) - { - pids[j] = _pid; - language[j] = _lang; - } - } - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - *numpids = j; - } - } -} - -void cPlayback::FindAllTeletextsubtitlePids(int */*pids*/, unsigned int *numpids, std::string */*language*/, int */*mags*/, int */*pages*/) -{ - hal_info("%s\n", __func__); - //int max_numpids = *numpids; - *numpids = 0; - -/* if (player && player->manager && player->manager->teletext) - { - char **TrackList = NULL; - player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("Teletext List\n"); - int i = 0, j = 0; - for (i = 0, j = 0; TrackList[i] != NULL; i += 2) - { - int type = 0; - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - if (j < max_numpids) - { - int _pid; - if (2 != sscanf(TrackList[i], "%d %*s %d %*d %*d", &_pid, &type)) - continue; - if (type != 2 && type != 5) // return subtitles only - continue; - pids[j] = _pid; - language[j] = std::string(TrackList[i]); - j++; - } - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - *numpids = j; - } - } */ -} - -int cPlayback::GetTeletextPid(void) -{ - hal_info("%s\n", __func__); - int pid = -1; - -/* if (player && player->manager && player->manager->teletext) - { - char **TrackList = NULL; - player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("Teletext List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i += 2) - { - int type = 0; - printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); - if (pid < 0) - { - if (2 != sscanf(TrackList[i], "%*d %d %*s %d %*d %*d", &pid, &type)) - continue; - if (type != 1) - pid = -1; - } - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - } - } */ - - printf("teletext pid id %d (0x%x)\n", pid, pid); - return pid; -} - -#if 0 -/* dummy functions for subtitles */ -void cPlayback::FindAllSubs(uint16_t * /*pids*/, unsigned short * /*supp*/, uint16_t *num, std::string * /*lang*/) -{ - *num = 0; -} - -bool cPlayback::SelectSubtitles(int /*pid*/) -{ - return false; -} -#endif - -void cPlayback::GetChapters(std::vector &positions, std::vector &titles) -{ - positions.clear(); - titles.clear(); - - if (player && player->manager && player->manager->chapter) - { - char **TrackList = NULL; - player->manager->chapter->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) - { - printf("%s: Chapter List\n", __func__); - int i = 0; - for (i = 0; TrackList[i] != NULL; i += 2) - { - printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); - int pos = atoi(TrackList[i]); - std::string title(TrackList[i + 1]); - positions.push_back(pos); - titles.push_back(title); - free(TrackList[i]); - free(TrackList[i + 1]); - } - free(TrackList); - } - } -} - -void cPlayback::GetMetadata(std::vector &keys, std::vector &values) -{ - keys.clear(); - values.clear(); - char **metadata = NULL; - if (player && player->playback) - { - player->playback->Command(player, PLAYBACK_METADATA, &metadata); - if (metadata) - { - for (char **m = metadata; *m;) - { - keys.push_back(*m); - free(*m++); - values.push_back(*m); - free(*m++); - } - free(metadata); - } - } -} - -cPlayback::cPlayback(int num __attribute__((unused))) -{ - hal_info("%s\n", __func__); - playing = false; - decoders_closed = false; - first = false; - player = NULL; -} - -cPlayback::~cPlayback() -{ - hal_info("%s\n", __func__); - - RequestAbort(); - mutex.lock(); - if (player) - { - free(player); - player = NULL; - } - mutex.unlock(); -} - -void cPlayback::RequestAbort() -{ - if (player && player->playback) - { - hal_info("%s\n", __func__); - mutex.lock(); - - if (player && player->playback && player->playback->isPlaying) - { - Stop(); - player->playback->abortRequested = 1; - } - else if(player->playback->isHttp && !player->playback->isPlaying &&!player->playback->abortRequested) - { - player->playback->abortRequested = 1; - } - - mutex.unlock(); - - } -} - -bool cPlayback::IsPlaying() -{ - if (player && player->playback) - return player->playback->isPlaying; - return false; -} - -uint64_t cPlayback::GetReadCount() -{ - if (player && player->playback) - { - return player->playback->readCount; - } - return 0; -} - -AVFormatContext *cPlayback::GetAVFormatContext() -{ - if (player && player->container && player->container->selectedContainer) - { - player->container->selectedContainer->Command(player, CONTAINER_GET_AVFCONTEXT, avft); - } - return avft; -} - -void cPlayback::ReleaseAVFormatContext() -{ - avft->streams = NULL; - avft->nb_streams = NULL; -} - -#if 0 -bool cPlayback::IsPlaying(void) const -{ - hal_info("%s\n", __func__); - - /* konfetti: there is no event/callback mechanism in libeplayer2 - * so in case of ending playback we have no information on a - * terminated stream currently (or did I oversee it?). - * So let's ask the player the state. - */ - if (playing) - { - return player->playback->isPlaying; - } - - return playing; -} -#endif diff --git a/libmipsbox/playback_libeplayer3.cpp b/libmipsbox/playback_libeplayer3.cpp new file mode 120000 index 0000000..a9ecfad --- /dev/null +++ b/libmipsbox/playback_libeplayer3.cpp @@ -0,0 +1 @@ +../libarmbox/playback_libeplayer3.cpp \ No newline at end of file diff --git a/libmipsbox/playback_libeplayer3.h b/libmipsbox/playback_libeplayer3.h deleted file mode 100644 index 783ea5a..0000000 --- a/libmipsbox/playback_libeplayer3.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef __PLAYBACK_LIBEPLAYER3_H__ -#define __PLAYBACK_LIBEPLAYER3_H__ - -#include -#include -#include - -typedef enum -{ - PLAYMODE_TS = 0, - PLAYMODE_FILE -} playmode_t; - -struct AVFormatContext; - -class cPlayback -{ - friend class CStreamInfo2; - - private: - static OpenThreads::Mutex mutex; - bool enabled; - bool playing, first; - bool no_probe; - bool got_vpts_ts; - int nPlaybackSpeed; - int mAudioStream; - int mSubtitleStream; - int mTeletextStream; - int64_t vpts_ts; - bool Stop(void); - bool decoders_closed; - playmode_t pm; - std::string fn_ts; - std::string fn_xml; - off64_t last_size; - int init_jump; - AVFormatContext *avft; - public: - cPlayback(int num = 0); - ~cPlayback(); - - bool Open(playmode_t PlayMode); - void Close(void); - bool Start(char *filename, int vpid, int vtype, int apid, int ac3, int duration, std::string headers = "", std::string filename2 = ""); - bool Start(std::string filename, std::string headers = "", std::string filename2 = ""); - bool SetAPid(int pid, bool ac3 = false); - bool SetVPid(int /*pid*/); - bool SetSubtitlePid(int pid); - bool SetTeletextPid(int pid); - int GetAPid(void) { return mAudioStream; } - int GetVPid(void) { return 0; } - int GetSubtitlePid(void) { return mSubtitleStream; } - int GetTeletextPid(void); - bool SetSpeed(int speed); - bool GetSpeed(int &speed) const; - bool GetPosition(int &position, int &duration); - void GetPts(uint64_t &pts); - bool SetPosition(int position, bool absolute = false); - void FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language); - void FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language); - void FindAllTeletextsubtitlePids(int */*pids*/, unsigned int *numpidt, std::string */*tlanguage*/, int */*mags*/, int */*pages*/); - void RequestAbort(void); - bool IsPlaying(void); - uint64_t GetReadCount(void); - - void GetChapters(std::vector &positions, std::vector &titles); - void GetMetadata(std::vector &keys, std::vector &values); - - AVFormatContext *GetAVFormatContext(); - void ReleaseAVFormatContext(); -#if 0 - void FindAllSubs(uint16_t *pids, unsigned short *supported, uint16_t *numpida, std::string *language); - bool SelectSubtitles(int pid); - - // Functions that are not used by movieplayer.cpp: - bool GetOffset(off64_t &offset); - bool IsPlaying(void) const; - bool IsEnabled(void) const; - void *GetHandle(void); - void *GetDmHandle(void); - int GetCurrPlaybackSpeed(void) const; - void PlaybackNotify(int Event, void *pData, void *pTag); - void DMNotify(int Event, void *pTsBuf, void *Tag); -#endif -}; - -#endif // __PLAYBACK_LIBEPLAYER3_H__ diff --git a/libmipsbox/playback_libeplayer3.h b/libmipsbox/playback_libeplayer3.h new file mode 120000 index 0000000..7eac198 --- /dev/null +++ b/libmipsbox/playback_libeplayer3.h @@ -0,0 +1 @@ +../libarmbox/playback_libeplayer3.h \ No newline at end of file diff --git a/libmipsbox/record.cpp b/libmipsbox/record.cpp deleted file mode 100644 index 6662aa8..0000000 --- a/libmipsbox/record.cpp +++ /dev/null @@ -1,403 +0,0 @@ -/* - * (C) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "record_lib.h" -#include "hal_debug.h" -#define hal_debug(args...) _hal_debug(HAL_DEBUG_RECORD, this, args) -#define hal_info(args...) _hal_info(HAL_DEBUG_RECORD, this, args) - -/* helper function to call the cpp thread loop */ -void *execute_record_thread(void *c) -{ - cRecord *obj = (cRecord *)c; - obj->RecordThread(); - return NULL; -} - -void *execute_writer_thread(void *c) -{ - cRecord *obj = (cRecord *)c; - obj->WriterThread(); - return NULL; -} - -cRecord::cRecord(int num, int bs_dmx, int bs) -{ - hal_info("%s %d\n", __func__, num); - dmx = NULL; - record_thread_running = false; - file_fd = -1; - exit_flag = RECORD_STOPPED; - dmx_num = num; - bufsize = bs; - bufsize_dmx = bs_dmx; - failureCallback = NULL; - failureData = NULL; -} - -cRecord::~cRecord() -{ - hal_info("%s: calling ::Stop()\n", __func__); - Stop(); - hal_info("%s: end\n", __func__); -} - -bool cRecord::Open(void) -{ - hal_info("%s\n", __func__); - exit_flag = RECORD_STOPPED; - return true; -} - -#if 0 -// unused -void cRecord::Close(void) -{ - hal_info("%s: \n", __func__); -} -#endif - -bool cRecord::Start(int fd, unsigned short vpid, unsigned short *apids, int numpids, uint64_t) -{ - hal_info("%s: fd %d, vpid 0x%03x\n", __func__, fd, vpid); - int i; - - if (!dmx) - dmx = new cDemux(dmx_num); - - dmx->Open(DMX_TP_CHANNEL, NULL, bufsize_dmx); - dmx->pesFilter(vpid); - - for (i = 0; i < numpids; i++) - dmx->addPid(apids[i]); - - file_fd = fd; - exit_flag = RECORD_RUNNING; - if (posix_fadvise(file_fd, 0, 0, POSIX_FADV_DONTNEED)) - perror("posix_fadvise"); - - i = pthread_create(&record_thread, 0, execute_record_thread, this); - if (i != 0) - { - exit_flag = RECORD_FAILED_READ; - errno = i; - hal_info("%s: error creating thread! (%m)\n", __func__); - delete dmx; - dmx = NULL; - return false; - } - record_thread_running = true; - return true; -} - -bool cRecord::Stop(void) -{ - hal_info("%s\n", __func__); - - if (exit_flag != RECORD_RUNNING) - hal_info("%s: status not RUNNING? (%d)\n", __func__, exit_flag); - - exit_flag = RECORD_STOPPED; - if (record_thread_running) - pthread_join(record_thread, NULL); - record_thread_running = false; - - /* We should probably do that from the destructor... */ - if (!dmx) - hal_info("%s: dmx == NULL?\n", __func__); - else - delete dmx; - dmx = NULL; - - if (file_fd != -1) - close(file_fd); - else - hal_info("%s: file_fd not open??\n", __func__); - file_fd = -1; - return true; -} - -bool cRecord::ChangePids(unsigned short /*vpid*/, unsigned short *apids, int numapids) -{ - std::vector pids; - int j; - bool found; - unsigned short pid; - hal_info("%s\n", __func__); - if (!dmx) { - hal_info("%s: DMX = NULL\n", __func__); - return false; - } - pids = dmx->pesfds; - /* the first PID is the video pid, so start with the second PID... */ - for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) { - found = false; - pid = (*i).pid; - for (j = 0; j < numapids; j++) { - if (pid == apids[j]) { - found = true; - break; - } - } - if (!found) - dmx->removePid(pid); - } - for (j = 0; j < numapids; j++) { - found = false; - for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) { - if ((*i).pid == apids[j]) { - found = true; - break; - } - } - if (!found) - dmx->addPid(apids[j]); - } - return true; -} - -bool cRecord::AddPid(unsigned short pid) -{ - std::vector pids; - hal_info("%s: \n", __func__); - if (!dmx) { - hal_info("%s: DMX = NULL\n", __func__); - return false; - } - pids = dmx->pesfds; - for (std::vector::const_iterator i = pids.begin(); i != pids.end(); ++i) { - if ((*i).pid == pid) - return true; /* or is it an error to try to add the same PID twice? */ - } - return dmx->addPid(pid); -} - -void cRecord::WriterThread() -{ - char threadname[17]; - strncpy(threadname, "WriterThread", sizeof(threadname)); - threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); - unsigned int chunk = 0; - while (!sem_wait(&sem)) { - if (!io_len[chunk]) // empty, assume end of recording - return; - unsigned char *p_buf = io_buf[chunk]; - size_t p_len = io_len[chunk]; - while (p_len) { - ssize_t written = write(file_fd, p_buf, p_len); - if (written < 0) - break; - p_len -= written; - p_buf += written; - } - if (posix_fadvise(file_fd, 0, 0, POSIX_FADV_DONTNEED)) - perror("posix_fadvise"); - chunk++; - chunk %= RECORD_WRITER_CHUNKS; - } -} - -void cRecord::RecordThread() -{ - hal_info("%s: begin\n", __func__); - char threadname[17]; - strncpy(threadname, "RecordThread", sizeof(threadname)); - threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); - int readsize = bufsize / 16; - int buf_pos = 0; - int count = 0; - int queued = 0; - uint8_t *buf; - struct aiocb a; - - buf = (uint8_t *)malloc(bufsize); - hal_info("BUFSIZE=0x%x READSIZE=0x%x\n", bufsize, readsize); - if (!buf) - { - exit_flag = RECORD_FAILED_MEMORY; - hal_info("%s: unable to allocate buffer! (out of memory)\n", __func__); - if (failureCallback) - failureCallback(failureData); - hal_info("%s: end\n", __func__); - pthread_exit(NULL); - } - - int val = fcntl(file_fd, F_GETFL); - if (fcntl(file_fd, F_SETFL, val|O_APPEND)) - hal_info("%s: O_APPEND? (%m)\n", __func__); - - memset(&a, 0, sizeof(a)); - a.aio_fildes = file_fd; - a.aio_sigevent.sigev_notify = SIGEV_NONE; - - dmx->Start(); - int overflow_count = 0; - bool overflow = false; - int r = 0; - while (exit_flag == RECORD_RUNNING) - { - if (buf_pos < bufsize) - { - if (overflow_count) { - hal_info("%s: Overflow cleared after %d iterations\n", __func__, overflow_count); - overflow_count = 0; - } - int toread = bufsize - buf_pos; - if (toread > readsize) - toread = readsize; - ssize_t s = dmx->Read(buf + buf_pos, toread, 50); - hal_debug("%s: buf_pos %6d s %6d / %6d\n", __func__, - buf_pos, (int)s, bufsize - buf_pos); - if (s < 0) - { - if (errno != EAGAIN && (errno != EOVERFLOW || !overflow)) - { - hal_info("%s: read failed: %m\n", __func__); - exit_flag = RECORD_FAILED_READ; - state = REC_STATUS_OVERFLOW; - break; - } - } - else - { - overflow = false; - buf_pos += s; - if (count > 100) - { - if (buf_pos < bufsize / 2) - continue; - } - else - { - count += 1; - } - } - } - else - { - if (!overflow) - overflow_count = 0; - overflow = true; - if (!(overflow_count % 10)) - hal_info("%s: buffer full! Overflow? (%d)\n", __func__, ++overflow_count); - state = REC_STATUS_SLOW; - } - r = aio_error(&a); - if (r == EINPROGRESS) - { - hal_debug("%s: aio in progress, free: %d\n", __func__, bufsize - buf_pos); - continue; - } - // not calling aio_return causes a memory leak --martii - r = aio_return(&a); - if (r < 0) - { - exit_flag = RECORD_FAILED_FILE; - hal_debug("%s: aio_return = %d (%m)\n", __func__, r); - break; - } - else - hal_debug("%s: aio_return = %d, free: %d\n", __func__, r, bufsize - buf_pos); - if (posix_fadvise(file_fd, 0, 0, POSIX_FADV_DONTNEED)) - perror("posix_fadvise"); - if (queued) - { - memmove(buf, buf + queued, buf_pos - queued); - buf_pos -= queued; - } - queued = buf_pos; - a.aio_buf = buf; - a.aio_nbytes = queued; - r = aio_write(&a); - if (r) - { - hal_info("%s: aio_write %d (%m)\n", __func__, r); - exit_flag = RECORD_FAILED_FILE; - break; - } - } - dmx->Stop(); - while (true) /* write out the unwritten buffer content */ - { - hal_debug("%s: run-out write, buf_pos %d\n", __func__, buf_pos); - r = aio_error(&a); - if (r == EINPROGRESS) - { - usleep(50000); - continue; - } - r = aio_return(&a); - if (r < 0) - { - exit_flag = RECORD_FAILED_FILE; - hal_info("%s: aio_result: %d (%m)\n", __func__, r); - break; - } - if (!queued) - break; - memmove(buf, buf + queued, buf_pos - queued); - buf_pos -= queued; - queued = buf_pos; - a.aio_buf = buf; - a.aio_nbytes = queued; - r = aio_write(&a); - } - free(buf); - -#if 0 - // TODO: do we need to notify neutrino about failing recording? - CEventServer eventServer; - eventServer.registerEvent2(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, "/tmp/neutrino.sock"); - stream2file_status2_t s; - s.status = exit_flag; - strncpy(s.filename,basename(myfilename),512); - s.filename[511] = '\0'; - strncpy(s.dir,dirname(myfilename),100); - s.dir[99] = '\0'; - eventServer.sendEvent(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, &s, sizeof(s)); - printf("[stream2file]: pthreads exit code: %i, dir: '%s', filename: '%s' myfilename: '%s'\n", exit_flag, s.dir, s.filename, myfilename); -#endif - - if ((exit_flag != RECORD_STOPPED) && failureCallback) - failureCallback(failureData); - hal_info("%s: end\n", __func__); - pthread_exit(NULL); -} - -int cRecord::GetStatus() -{ - return (exit_flag == RECORD_STOPPED) ? REC_STATUS_STOPPED : REC_STATUS_OK; -} - -void cRecord::ResetStatus() -{ - return; -} diff --git a/libmipsbox/record.cpp b/libmipsbox/record.cpp new file mode 120000 index 0000000..bd5779b --- /dev/null +++ b/libmipsbox/record.cpp @@ -0,0 +1 @@ +../libarmbox/record.cpp \ No newline at end of file diff --git a/libmipsbox/record_lib.h b/libmipsbox/record_lib.h deleted file mode 100644 index 9e554cd..0000000 --- a/libmipsbox/record_lib.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef __RECORD_LIB_H__ -#define __RECORD_LIB_H__ - -#include -#include "dmx_hal.h" - -#define REC_STATUS_OK 0 -#define REC_STATUS_SLOW 1 -#define REC_STATUS_OVERFLOW 2 -#define REC_STATUS_STOPPED 4 - -typedef enum { - RECORD_RUNNING, - RECORD_STOPPED, - RECORD_FAILED_READ, /* failed to read from DMX */ - RECORD_FAILED_OVERFLOW, /* cannot write fast enough */ - RECORD_FAILED_FILE, /* cannot write to file */ - RECORD_FAILED_MEMORY /* out of memory */ -} record_state_t; - -class cRecord -{ - private: - int file_fd; - int dmx_num; - cDemux *dmx; - pthread_t record_thread; - bool record_thread_running; - record_state_t exit_flag; - int state; - int bufsize; - int bufsize_dmx; - void (*failureCallback)(void *); - void *failureData; - - sem_t sem; -#define RECORD_WRITER_CHUNKS 16 - unsigned char *io_buf[RECORD_WRITER_CHUNKS]; - size_t io_len[RECORD_WRITER_CHUNKS]; - public: - cRecord(int num = 0, int bs_dmx = 2048 * 1024, int bs = 4096 * 1024); - void setFailureCallback(void (*f)(void *), void *d) { failureCallback = f; failureData = d; } - ~cRecord(); - - bool Open(); - bool Start(int fd, unsigned short vpid, unsigned short *apids, int numapids, uint64_t ch = 0); - bool Stop(void); - bool AddPid(unsigned short pid); - int GetStatus(); - void ResetStatus(); - bool ChangePids(unsigned short vpid, unsigned short *apids, int numapids); - - void RecordThread(); - void WriterThread(); -}; - -#endif // __RECORD_LIB_H__ diff --git a/libmipsbox/record_lib.h b/libmipsbox/record_lib.h new file mode 120000 index 0000000..8104a0c --- /dev/null +++ b/libmipsbox/record_lib.h @@ -0,0 +1 @@ +../libarmbox/record_lib.h \ No newline at end of file diff --git a/libmipsbox/video.cpp b/libmipsbox/video.cpp deleted file mode 100644 index 30d50c0..0000000 --- a/libmipsbox/video.cpp +++ /dev/null @@ -1,1290 +0,0 @@ -/* - * (C) 2002-2003 Andreas Oberritter - * (C) 2010-2013, 2015 Stefan Seyfried - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include "video_lib.h" -#include "hal_debug.h" -#include "hdmi_cec.h" - -#include - -extern "C" -{ -#include -#include -#include -#include -} - -#define hal_debug(args...) _hal_debug(HAL_DEBUG_VIDEO, this, args) -#define hal_info(args...) _hal_info(HAL_DEBUG_VIDEO, this, args) -#define hal_debug_c(args...) _hal_debug(HAL_DEBUG_VIDEO, NULL, args) -#define hal_info_c(args...) _hal_info(HAL_DEBUG_VIDEO, NULL, args) - -#define fop(cmd, args...) ({ \ - int _r; \ - if (fd >= 0) { \ - if ((_r = ::cmd(fd, args)) < 0) \ - hal_info(#cmd"(fd, "#args")\n"); \ - else \ - hal_debug(#cmd"(fd, "#args")\n");\ - } \ - else { _r = fd; } \ - _r; \ -}) - -#ifndef VIDEO_GET_SIZE -#define VIDEO_GET_SIZE _IOR('o', 55, video_size_t) -#endif -#ifndef VIDEO_GET_FRAME_RATE -#define VIDEO_GET_FRAME_RATE _IOR('o', 56, unsigned int) -#endif - -cVideo * videoDecoder = NULL; -cVideo * pipDecoder = NULL; - -int system_rev = 0; - -static bool stillpicture = false; - -static const char *VDEV[] = { - "/dev/dvb/adapter0/video0", - "/dev/dvb/adapter0/video1", - "/dev/dvb/adapter0/video2", - "/dev/dvb/adapter0/video3" -}; -static const char *VMPEG_aspect[] = { - "/proc/stb/vmpeg/0/aspect", - "/proc/stb/vmpeg/1/aspect", - "/proc/stb/vmpeg/2/aspect", - "/proc/stb/vmpeg/3/aspect" -}; - -static const char *VMPEG_xres[] = { - "/proc/stb/vmpeg/0/xres", - "/proc/stb/vmpeg/1/xres", - "/proc/stb/vmpeg/2/xres", - "/proc/stb/vmpeg/3/xres" -}; - -static const char *VMPEG_yres[] = { - "/proc/stb/vmpeg/0/yres", - "/proc/stb/vmpeg/1/yres", - "/proc/stb/vmpeg/2/yres", - "/proc/stb/vmpeg/3/yres" -}; - -static const char *VMPEG_dst_height[] = { - "/proc/stb/vmpeg/0/dst_height", - "/proc/stb/vmpeg/1/dst_height", - "/proc/stb/vmpeg/2/dst_height", - "/proc/stb/vmpeg/3/dst_height" -}; - -static const char *VMPEG_dst_width[] = { - "/proc/stb/vmpeg/0/dst_width", - "/proc/stb/vmpeg/1/dst_width", - "/proc/stb/vmpeg/2/dst_width", - "/proc/stb/vmpeg/3/dst_width" -}; - -static const char *VMPEG_dst_top[] = { - "/proc/stb/vmpeg/0/dst_top", - "/proc/stb/vmpeg/1/dst_top", - "/proc/stb/vmpeg/2/dst_top", - "/proc/stb/vmpeg/3/dst_top" -}; - -static const char *VMPEG_dst_left[] = { - "/proc/stb/vmpeg/0/dst_left", - "/proc/stb/vmpeg/1/dst_left", - "/proc/stb/vmpeg/2/dst_left", - "/proc/stb/vmpeg/3/dst_left" -}; - -static const char *VMPEG_framerate[] = { - "/proc/stb/vmpeg/0/framerate", - "/proc/stb/vmpeg/1/framerate", - "/proc/stb/vmpeg/2/framerate", - "/proc/stb/vmpeg/3/framerate" -}; - -static const char *vid_modes[] = { - "pal", // VIDEO_STD_NTSC - "pal", // VIDEO_STD_SECAM - "pal", // VIDEO_STD_PAL - "480p", // VIDEO_STD_480P - "576p50", // VIDEO_STD_576P - "720p60", // VIDEO_STD_720P60 - "1080i60", // VIDEO_STD_1080I60 - "720p50", // VIDEO_STD_720P50 - "1080i50", // VIDEO_STD_1080I50 - "1080p30", // VIDEO_STD_1080P30 - "1080p24", // VIDEO_STD_1080P24 - "1080p25", // VIDEO_STD_1080P25 - "1080p50", // VIDEO_STD_1080P50 - "1080p60", // VIDEO_STD_1080P60 - "1080p2397", // VIDEO_STD_1080P2397 - "1080p2997", // VIDEO_STD_1080P2997 - "2160p24", // VIDEO_STD_2160P24 - "2160p25", // VIDEO_STD_2160P25 - "2160p30", // VIDEO_STD_2160P30 - "2160p50", // VIDEO_STD_2160P50 - "720p50" // VIDEO_STD_AUTO -}; - -#define VIDEO_STREAMTYPE_MPEG2 0 -#define VIDEO_STREAMTYPE_MPEG4_H264 1 -#define VIDEO_STREAMTYPE_VC1 3 -#define VIDEO_STREAMTYPE_MPEG4_Part2 4 -#define VIDEO_STREAMTYPE_VC1_SM 5 -#define VIDEO_STREAMTYPE_MPEG1 6 -#define VIDEO_STREAMTYPE_H265_HEVC 7 -#define VIDEO_STREAMTYPE_AVS 16 - -ssize_t write_all(int fd, const void *buf, size_t count) -{ - int retval; - char *ptr = (char*)buf; - size_t handledcount = 0; - while (handledcount < count) - { - retval = write(fd, &ptr[handledcount], count - handledcount); - if (retval == 0) - return -1; - if (retval < 0) - { - if (errno == EINTR) - continue; - return retval; - } - handledcount += retval; - } - return handledcount; -} - -void init_parameters(AVFrame* in_frame, AVCodecContext *codec_context) -{ - /* put sample parameters */ - codec_context->bit_rate = 400000; - /* resolution must be a multiple of two */ - codec_context->width = (in_frame->width/2)*2; - codec_context->height = (in_frame->height/2)*2; - /* frames per second */ - codec_context->time_base = (AVRational ) { 1, 60 }; - codec_context->gop_size = 10; /* emit one intra frame every ten frames */ - codec_context->max_b_frames = 1; - codec_context->pix_fmt = AV_PIX_FMT_YUV420P; -} - -void write_frame(AVFrame* in_frame, int fd) -{ - if(in_frame == NULL) - return; - static const unsigned char pes_header[] = {0x0, 0x0, 0x1, 0xe0, 0x00, 0x00, 0x80, 0x80, 0x5, 0x21, 0x0, 0x1, 0x0, 0x1}; - - AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO); - if (codec) - { - AVCodecContext *codec_context = avcodec_alloc_context3(codec); - if (codec_context) - { - init_parameters(in_frame, codec_context); - if (avcodec_open2(codec_context, codec, 0) != -1){ - AVPacket pkt; - av_init_packet(&pkt); - /* encode the image */ -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) - int got_output = 0; - int ret = avcodec_encode_video2(codec_context, &pkt, in_frame, &got_output); - if (ret != -1){ -#else - int ret = avcodec_send_frame(codec_context, in_frame); - if (!ret) { - /* signalling end of stream */ - ret = avcodec_send_frame(codec_context, NULL); - } - if (!ret) { -#endif - int i = 1; - /* get the delayed frames */ - in_frame->pts = i; -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) - ret = avcodec_encode_video2(codec_context, &pkt, 0, &got_output); - if (ret != -1 && got_output){ -#else - ret = avcodec_receive_packet(codec_context, &pkt); - if (!ret) { -#endif - if ((pkt.data[3] >> 4) != 0xE){ - write_all(fd, pes_header, sizeof(pes_header)); - }else{ - pkt.data[4] = pkt.data[5] = 0x00; - } - write_all(fd,pkt.data, pkt.size); - av_packet_unref(&pkt); - } - } - } - avcodec_close(codec_context); - av_free(codec_context); - } - } -} - -int decode_frame(AVCodecContext *codecContext,AVPacket &packet, int fd) -{ - AVFrame *frame = av_frame_alloc(); - if(frame){ -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) - int decode_ok = 0; - if ((avcodec_decode_video2(codecContext, frame, &decode_ok, &packet)) < 0 || !decode_ok){ - av_frame_free(&frame); - return -1; - } -#else - int ret; - ret = avcodec_send_packet(codecContext, &packet); - // In particular, we don't expect AVERROR(EAGAIN), because we read all - // decoded frames with avcodec_receive_frame() until done. - if (ret < 0) { - av_frame_free(&frame); - return -1; - } - ret = avcodec_receive_frame(codecContext, frame); - if (ret < 0) { - av_frame_free(&frame); - return -1; - } -#endif - AVFrame *dest_frame = av_frame_alloc(); - if(dest_frame){ - dest_frame->height = (frame->height/2)*2; - dest_frame->width = (frame->width/2)*2; - dest_frame->format = AV_PIX_FMT_YUV420P; - av_frame_get_buffer(dest_frame, 32); - struct SwsContext *convert = NULL; - convert = sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format, dest_frame->width, dest_frame->height, AV_PIX_FMT_YUVJ420P, SWS_FAST_BILINEAR, NULL, NULL, NULL); - if(convert){ - sws_scale(convert, frame->data, frame->linesize, 0, frame->height, dest_frame->data, dest_frame->linesize); - sws_freeContext(convert); - } - write_frame(dest_frame, fd); - av_frame_free(&dest_frame); - } - av_frame_free(&frame); - } - return 0; - -} - -AVCodecContext* open_codec(AVMediaType mediaType, AVFormatContext* formatContext) -{ - AVCodec * codec = NULL; - AVCodecContext * codecContext = NULL; - int stream_index; -#if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT( 57,25,101 )) - stream_index = av_find_best_stream(formatContext, mediaType, -1, -1, NULL, 0); - if (stream_index >= 0) { - codecContext = formatContext->streams[stream_index]->codec; - if (codecContext) { - codec = avcodec_find_decoder(codecContext->codec_id); - if (codec) { - if ((avcodec_open2(codecContext, codec, NULL)) != 0) { - return NULL; - } - } - return codecContext; - } - } - return NULL; -#else - stream_index = av_find_best_stream(formatContext, mediaType, -1, -1, &codec, 0); - if (stream_index >= 0) { - codec = avcodec_find_decoder(formatContext->streams[stream_index]->codecpar->codec_id); - if (codec) { - codecContext = avcodec_alloc_context3(codec); - } - if (codecContext) { - if ((avcodec_open2(codecContext, codec, NULL)) != 0) { - return NULL; - } - return codecContext; - } - } - return NULL; -#endif -} - -int image_to_mpeg2(const char *image_name, int fd) -{ - int ret = 0; -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100) - av_register_all(); - avcodec_register_all(); -#endif - - AVFormatContext *formatContext = avformat_alloc_context(); - if (formatContext && (ret = avformat_open_input(&formatContext, image_name, NULL, NULL)) == 0){ - AVCodecContext *codecContext = open_codec(AVMEDIA_TYPE_VIDEO, formatContext); - if(codecContext){ - AVPacket packet; - av_init_packet(&packet); - if ((ret = av_read_frame(formatContext, &packet)) !=-1){ - if((ret = decode_frame(codecContext, packet, fd)) != 1){ - /* add sequence end code to have a real mpeg file */ - uint8_t endcode[] = { 0, 0, 1, 0xb7 }; - write_all(fd,endcode, sizeof(endcode)); - } - av_packet_unref(&packet); - } - avcodec_close(codecContext); - av_free(codecContext); - } - avformat_close_input(&formatContext); - } - av_free(formatContext); - return ret; -} -enum{ENCODER,AUX}; -void setAVInput(int val) -{ - int input_fd = open("/proc/stb/avs/0/input", O_WRONLY); - if(input_fd){ - const char *input[] = {"encoder", "aux"}; - write(input_fd, input[val], strlen(input[val])); - close(input_fd); - } -} - -cVideo::cVideo(int, void *, void *, unsigned int unit) -{ - hal_debug("%s unit %u\n", __func__, unit); - - brightness = -1; - contrast = -1; - saturation = -1; - hue = -1; - video_standby = 0; - blank_mode = 0; - if (unit > 1) { - hal_info("%s: unit %d out of range, setting to 0\n", __func__, unit); - devnum = 0; - } else - devnum = unit; - fd = -1; - openDevice(); - setAVInput(ENCODER); -} - -cVideo::~cVideo(void) -{ - if(fd >= 0) - setAVInput(AUX); - if (hdmi_cec::getInstance()->standby_cec_activ && fd >= 0) - hdmi_cec::getInstance()->SetCECState(true); - - closeDevice(); -} - -void cVideo::openDevice(void) -{ - int n = 0; - hal_debug("#%d: %s\n", devnum, __func__); - /* todo: this fd checking is racy, should be protected by a lock */ - if (fd != -1) /* already open */ - return; -retry: - if ((fd = open(VDEV[devnum], O_RDWR|O_CLOEXEC)) < 0) - { - if (errno == EBUSY) - { - /* sometimes we get busy quickly after close() */ - usleep(50000); - if (++n < 10) - goto retry; - } - hal_info("#%d: %s cannot open %s: %m, retries %d\n", devnum, __func__, VDEV[devnum], n); - } - playstate = VIDEO_STOPPED; -} - -void cVideo::closeDevice(void) -{ - hal_debug("%s\n", __func__); - /* looks like sometimes close is unhappy about non-empty buffers */ -// Start(); - if (fd >= 0) - close(fd); - fd = -1; - playstate = VIDEO_STOPPED; -} - -int cVideo::setAspectRatio(int aspect, int mode) -{ - static const char *a[] = { "n/a", "4:3", "14:9", "16:9" }; -// static const char *m[] = { "panscan", "letterbox", "bestfit", "nonlinear", "(unset)" }; - static const char *m[] = { "letterbox", "panscan", "bestfit", "nonlinear", "(unset)" }; - int n; - - int mo = (mode < 0||mode > 3) ? 4 : mode; - hal_debug("%s: a:%d m:%d %s\n", __func__, aspect, mode, m[mo]); - - if (aspect > 3 || aspect == 0) - hal_info("%s: invalid aspect: %d\n", __func__, aspect); - else if (aspect > 0) /* -1 == don't set */ - { - hal_debug("%s: /proc/stb/video/aspect -> %s\n", __func__, a[aspect]); - n = proc_put("/proc/stb/video/aspect", a[aspect], strlen(a[aspect])); - if (n < 0) - hal_info("%s: proc_put /proc/stb/video/aspect (%m)\n", __func__); - } - - if (mode == -1) - return 0; - - hal_debug("%s: /proc/stb/video/policy -> %s\n", __func__, m[mo]); - n = proc_put("/proc/stb/video/policy", m[mo], strlen(m[mo])); - if (n < 0) - return 1; - return 0; -} - -int cVideo::getAspectRatio(void) -{ - video_size_t s; - if (fd == -1) - { - /* in movieplayer mode, fd is not opened -> fall back to procfs */ - int n = proc_get_hex(VMPEG_aspect[devnum]); - return n; - } - if (fop(ioctl, VIDEO_GET_SIZE, &s) < 0) - { - hal_info("%s: VIDEO_GET_SIZE %m\n", __func__); - return -1; - } - hal_debug("#%d: %s: %d\n", devnum, __func__, s.aspect_ratio); - return s.aspect_ratio * 2 + 1; -} - -int cVideo::setCroppingMode(int /*vidDispMode_t format*/) -{ - return 0; -#if 0 - croppingMode = format; - const char *format_string[] = { "norm", "letterbox", "unknown", "mode_1_2", "mode_1_4", "mode_2x", "scale", "disexp" }; - const char *f; - if (format >= VID_DISPMODE_NORM && format <= VID_DISPMODE_DISEXP) - f = format_string[format]; - else - f = "ILLEGAL format!"; - hal_debug("%s(%d) => %s\n", __FUNCTION__, format, f); - return fop(ioctl, MPEG_VID_SET_DISPMODE, format); -#endif -} - -int cVideo::Start(void * /*PcrChannel*/, unsigned short /*PcrPid*/, unsigned short /*VideoPid*/, void * /*hChannel*/) -{ - hal_debug("#%d: %s playstate=%d\n", devnum, __func__, playstate); -#if 0 - if (playstate == VIDEO_PLAYING) - return 0; - if (playstate == VIDEO_FREEZED) /* in theory better, but not in practice :-) */ - fop(ioctl, MPEG_VID_CONTINUE); -#endif - /* implicitly do StopPicture() on video->Start() */ - if (stillpicture) { - hal_info("%s: stillpicture == true, doing implicit StopPicture()\n", __func__); - stillpicture = false; - Stop(1); - } - playstate = VIDEO_PLAYING; - fop(ioctl, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX); - int res = fop(ioctl, VIDEO_PLAY); - if (brightness > -1) { - SetControl(VIDEO_CONTROL_BRIGHTNESS, brightness); - brightness = -1; - } - if (contrast > -1) { - SetControl(VIDEO_CONTROL_CONTRAST, contrast); - contrast = -1; - } - if (saturation > -1) { - SetControl(VIDEO_CONTROL_SATURATION, saturation); - saturation = -1; - } - if (hue > -1) { - SetControl(VIDEO_CONTROL_HUE, hue); - hue = -1; - } - blank_mode = 0; - return res; -} - -int cVideo::Stop(bool blank) -{ - hal_debug("#%d: %s(%d)\n", devnum, __func__, blank); - if (stillpicture) - { - hal_debug("%s: stillpicture == true\n", __func__); - return -1; - } - playstate = blank ? VIDEO_STOPPED : VIDEO_FREEZED; - blank_mode = blank; - return fop(ioctl, VIDEO_STOP, blank ? 1 : 0); -} - -int cVideo::setBlank(int enable) -{ - fop(ioctl, VIDEO_PLAY); - fop(ioctl, VIDEO_CONTINUE); - if (enable) - { - video_still_picture sp = { NULL, 0 }; - fop(ioctl, VIDEO_STILLPICTURE, &sp); - return Stop(1); - } - else - return Start(); -} - -int cVideo::SetVideoSystem(int video_system, bool remember) -{ - hal_debug("%s(%d, %d)\n", __func__, video_system, remember); - char current[32]; - - if (video_system > VIDEO_STD_MAX) - { - hal_info("%s: video_system (%d) > VIDEO_STD_MAX (%d)\n", __func__, video_system, VIDEO_STD_MAX); - return -1; - } - int ret = proc_get("/proc/stb/video/videomode", current, 32); - if (strcmp(current, vid_modes[video_system]) == 0) - { - hal_info("%s: video_system %d (%s) already set, skipping\n", __func__, video_system, current); - return 0; - } - hal_info("%s: old: '%s' new: '%s'\n", __func__, current, vid_modes[video_system]); - bool stopped = false; - if (playstate == VIDEO_PLAYING) - { - hal_info("%s: playstate == VIDEO_PLAYING, stopping video\n", __func__); - Stop(); - stopped = true; - } - ret = proc_put("/proc/stb/video/videomode", vid_modes[video_system],strlen(vid_modes[video_system])); - if (stopped) - Start(); - - return ret; -} - -int cVideo::GetVideoSystem(void) -{ - char current[32]; - proc_get("/proc/stb/video/videomode", current, 32); - for (int i = 0; vid_modes[i]; i++) - { - if (strcmp(current, vid_modes[i]) == 0) - return i; - } - hal_info("%s: could not find '%s' mode, returning VIDEO_STD_720P50\n", __func__, current); - return VIDEO_STD_720P50; -} - -void cVideo::GetVideoSystemFormatName(cs_vs_format_t *format, int system) -{ - if (system == -1) - system = GetVideoSystem(); - if (system < 0 || system > VIDEO_STD_1080P50) { - hal_info("%s: invalid system %d\n", __func__, system); - strcpy(format->format, "invalid"); - } else - strcpy(format->format, vid_modes[system]); -} - -int cVideo::getPlayState(void) -{ - return playstate; -} - -void cVideo::SetVideoMode(analog_mode_t mode) -{ - hal_debug("#%d: %s(%d)\n", devnum, __func__, mode); - if (!(mode & ANALOG_SCART_MASK)) - { - hal_debug("%s: non-SCART mode ignored\n", __func__); - return; - } - const char *m; - switch(mode) - { - case ANALOG_SD_YPRPB_SCART: - m = "yuv"; - break; - case ANALOG_SD_RGB_SCART: - m = "rgb"; - break; - default: - hal_info("%s unknown mode %d\n", __func__, mode); - m = "rgb"; - break; /* default to rgb */ - } - proc_put("/proc/stb/avs/0/colorformat", m, strlen(m)); -} - -void cVideo::ShowPicture(const char * fname) -{ - hal_info("%s(%s)\n", __func__, fname); - if (video_standby) - { - /* does not work and the driver does not seem to like it */ - hal_info("%s: video_standby == true\n", __func__); - return; - } - struct stat st; - if (stat(fname, &st)){ - return; - } - closeDevice(); - openDevice(); - if (fd >= 0) - { - usleep(50000);//workaround for switch to radiomode - stillpicture = true; - ioctl(fd, VIDEO_SET_STREAMTYPE, VIDEO_STREAMTYPE_MPEG2); // set to mpeg2 - ioctl(fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY); - ioctl(fd, VIDEO_PLAY); - ioctl(fd, VIDEO_CONTINUE); - ioctl(fd, VIDEO_CLEAR_BUFFER); - image_to_mpeg2(fname, fd); - unsigned char iframe[8192]; - memset(iframe,0xff,sizeof(iframe)); - write_all(fd, iframe, 8192); - usleep(150000); - ioctl(fd, VIDEO_STOP, 0); - ioctl(fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX); - } - return; -} - -void cVideo::StopPicture() -{ - hal_debug("%s\n", __func__); - stillpicture = false; - Stop(1); - closeDevice(); - openDevice(); -} - -void cVideo::Standby(unsigned int bOn) -{ - hal_debug("%s(%d)\n", __func__, bOn); - if (bOn) - { - closeDevice(); - setAVInput(AUX); - } - else - { - openDevice(); - setAVInput(ENCODER); - } - video_standby = bOn; - hdmi_cec::getInstance()->SetCECState(video_standby); -} - -int cVideo::getBlank(void) -{ -#if 0 - int ret = proc_get_hex(VMPEG_xres[devnum]); - hal_debug("%s => %d\n", __func__, !ret); - return !ret; -#else - hal_debug("%s => %d\n", __func__, blank_mode); - return blank_mode; -#endif -} - -void cVideo::Pig(int x, int y, int w, int h, int osd_w, int osd_h, int startx, int starty, int endx, int endy) -{ - char buffer[64]; - int _x, _y, _w, _h; - /* the target "coordinates" seem to be in a PAL sized plane - * TODO: check this in the driver sources */ - int xres = 720; /* proc_get_hex("/proc/stb/vmpeg/0/xres") */ - int yres = 576; /* proc_get_hex("/proc/stb/vmpeg/0/yres") */ - hal_debug("#%d %s: x:%d y:%d w:%d h:%d ow:%d oh:%d\n", devnum, __func__, x, y, w, h, osd_w, osd_h); - if (x == -1 && y == -1 && w == -1 && h == -1) - { - _w = xres; - _h = yres; - _x = 0; - _y = 0; - } - else - { - // need to do some additional adjustments because osd border is handled by blitter - x += startx; - x *= endx - startx + 1; - y += starty; - y *= endy - starty + 1; - w *= endx - startx + 1; - h *= endy - starty + 1; - _x = x * xres / osd_w; - _w = w * xres / osd_w; - _y = y * yres / osd_h; - _h = h * yres / osd_h; - _x /= 1280; - _y /= 720; - _w /= 1280; - _h /= 720; - } - hal_debug("#%d %s: x:%d y:%d w:%d h:%d xr:%d yr:%d\n", devnum, __func__, _x, _y, _w, _h, xres, yres); - sprintf(buffer, "%x", _x); - proc_put(VMPEG_dst_left[devnum], buffer, strlen(buffer)); - - sprintf(buffer, "%x", _y); - proc_put(VMPEG_dst_top[devnum], buffer, strlen(buffer)); - - sprintf(buffer, "%x", _w); - proc_put(VMPEG_dst_width[devnum], buffer, strlen(buffer)); - - sprintf(buffer, "%x", _h); - proc_put(VMPEG_dst_height[devnum], buffer, strlen(buffer)); -} - -static inline int rate2csapi(int rate) -{ - switch (rate) - { - case 23976: - return 0; - case 24000: - return 1; - case 25000: - return 2; - case 29970: - return 3; - case 30000: - return 4; - case 50000: - return 5; - case 59940: - return 6; - case 60000: - return 7; - default: - break; - } - return -1; -} - -void cVideo::getPictureInfo(int &width, int &height, int &rate) -{ - video_size_t s; - int r; - if (fd == -1) - { - /* in movieplayer mode, fd is not opened -> fall back to procfs */ - char buf[16]; - int n = proc_get(VMPEG_framerate[devnum], buf, 16); - if (n > 0) - sscanf(buf, "%i", &r); - width = proc_get_hex(VMPEG_xres[devnum]); - height = proc_get_hex(VMPEG_yres[devnum]); - rate = rate2csapi(r); - return; - } - ioctl(fd, VIDEO_GET_SIZE, &s); - ioctl(fd, VIDEO_GET_FRAME_RATE, &r); - rate = rate2csapi(r); - height = s.h; - width = s.w; - hal_debug("#%d: %s: rate: %d, width: %d height: %d\n", devnum, __func__, rate, width, height); -} - -void cVideo::SetSyncMode(AVSYNC_TYPE mode) -{ - hal_debug("%s %d\n", __func__, mode); - /* - * { 0, LOCALE_OPTIONS_OFF }, - * { 1, LOCALE_OPTIONS_ON }, - * { 2, LOCALE_AUDIOMENU_AVSYNC_AM } - */ -}; - -int cVideo::SetStreamType(VIDEO_FORMAT type) -{ - static const char *VF[] = { - "VIDEO_FORMAT_MPEG2", - "VIDEO_FORMAT_MPEG4", - "VIDEO_FORMAT_VC1", - "VIDEO_FORMAT_JPEG", - "VIDEO_FORMAT_GIF", - "VIDEO_FORMAT_PNG" - }; - int t; - hal_debug("#%d: %s type=%s\n", devnum, __func__, VF[type]); - - switch (type) - { - case VIDEO_FORMAT_MPEG4_H264: - t = VIDEO_STREAMTYPE_MPEG4_H264; - break; - case VIDEO_FORMAT_MPEG4_H265: - t = VIDEO_STREAMTYPE_H265_HEVC; - break; - case VIDEO_FORMAT_AVS: - t = VIDEO_STREAMTYPE_AVS; - break; - case VIDEO_FORMAT_VC1: - t = VIDEO_STREAMTYPE_VC1; - break; - case VIDEO_FORMAT_MPEG2: - default: - t = VIDEO_STREAMTYPE_MPEG2; - break; - } - - if (ioctl(fd, VIDEO_SET_STREAMTYPE, t) < 0) - hal_info("%s VIDEO_SET_STREAMTYPE(%d) failed: %m\n", __func__, t); - return 0; -} - -int64_t cVideo::GetPTS(void) -{ - int64_t pts = 0; - if (ioctl(fd, VIDEO_GET_PTS, &pts) < 0) - hal_info("%s: GET_PTS failed (%m)\n", __func__); - return pts; -} - -void cVideo::SetDemux(cDemux *) -{ - hal_debug("#%d %s not implemented yet\n", devnum, __func__); -} - -void cVideo::SetControl(int control, int value) -{ - const char *p = NULL; - switch (control) { - case VIDEO_CONTROL_BRIGHTNESS: - brightness = value; - p = "/proc/stb/vmpeg/0/pep_brightness"; - break; - case VIDEO_CONTROL_CONTRAST: - contrast = value; - p = "/proc/stb/vmpeg/0/pep_contrast"; - break; - case VIDEO_CONTROL_SATURATION: - saturation = value; - p = "/proc/stb/vmpeg/0/pep_saturation"; - break; - case VIDEO_CONTROL_HUE: - hue = value; - p = "/proc/stb/vmpeg/0/pep_hue"; - break; - case VIDEO_CONTROL_SHARPNESS: - sharpness = value; - p = "/proc/stb/vmpeg/0/pep_sharpness"; - break; - case VIDEO_CONTROL_BLOCK_NOISE_REDUCTION: - block_noise_reduction = value; - p = "/proc/stb/vmpeg/0/pep_block_noise_reduction"; - break; - case VIDEO_CONTROL_MOSQUITO_NOISE_REDUCTION: - mosquito_noise_reduction = value; - p = "/proc/stb/vmpeg/0/pep_mosquito_noise_reduction"; - break; - case VIDEO_CONTROL_DIGITAL_CONTOUR_REMOVAL: - digital_contour_removal = value; - p = "/proc/stb/vmpeg/0/pep_digital_contour_removal"; - break; - case VIDEO_CONTROL_AUTO_FLESH: - auto_flesh = value; - p = "/proc/stb/vmpeg/0/pep_auto_flesh"; - break; - case VIDEO_CONTROL_GREEN_BOOST: - green_boost = value; - p = "/proc/stb/vmpeg/0/pep_green_boost"; - break; - case VIDEO_CONTROL_BLUE_BOOST: - blue_boost = value; - p = "/proc/stb/vmpeg/0/pep_blue_boost"; - break; - case VIDEO_CONTROL_DYNAMIC_CONTRAST: - dynamic_contrast = value; - p = "/proc/stb/vmpeg/0/pep_dynamic_contrast"; - break; - case VIDEO_CONTROL_SCALER_SHARPNESS: - scaler_sharpness = value; - p = "/proc/stb/vmpeg/0/pep_scaler_sharpness"; - break; - case VIDEO_CONTROL_ZAPPING_MODE: - zapping_mode = value; - const char *mode_zapping[] = { "mute", "hold", "mutetilllock", "holdtilllock"}; - proc_put("/proc/stb/video/zapmode", mode_zapping[zapping_mode], strlen(mode_zapping[zapping_mode])); -// proc_put("/proc/stb/video/zapping_mode", mode_zapping[zapping_mode], strlen(mode_zapping[zapping_mode])); - break; - } - if (p) { - char buf[20]; - int fix_value = value * 256; - int len = snprintf(buf, sizeof(buf), "%.8X", fix_value); - if (len < (int) sizeof(buf)) - proc_put(p, buf, len); - } -} - -void cVideo::SetColorFormat(COLOR_FORMAT color_format) -{ - const char *p = NULL; - switch(color_format) { - case COLORFORMAT_RGB: - p = "rgb"; - break; - case COLORFORMAT_YUV: - p = "yuv"; - break; - case COLORFORMAT_CVBS: - p = "cvbs"; - break; - case COLORFORMAT_SVIDEO: - p = "svideo"; - break; - case COLORFORMAT_HDMI_AUTO: - p = "Edid(Auto)"; - break; - case COLORFORMAT_HDMI_RGB: - p = "Hdmi_Rgb"; - break; - case COLORFORMAT_HDMI_YCBCR444: - p = "444"; - break; - case COLORFORMAT_HDMI_YCBCR422: - p = "422"; - break; - case COLORFORMAT_HDMI_YCBCR420: - p = "420"; - break; - } - if (p) - proc_put("/proc/stb/video/hdmi_colorspace", p, strlen(p)); -} - -bool getvideo2(unsigned char *video, int xres, int yres) -{ - bool ret = false; - if(video == NULL) - return ret; - char videosnapshot[] = "/dev/dvb/adapter0/video0"; - int fd_video = open(videosnapshot, O_RDONLY); - if (fd_video < 0) { - perror(videosnapshot); - return ret; - } - ssize_t r = read(fd_video, video, xres * yres * 3); - if(r){ - ret = true; - } - close(fd_video); - return ret; -} -static bool swscale(unsigned char *src, unsigned char *dst, int sw, int sh, int dw, int dh, AVPixelFormat sfmt) -{ - bool ret = false; - int len = 0; - struct SwsContext *scale = NULL; - scale = sws_getCachedContext(scale, sw, sh, sfmt, dw, dh, AV_PIX_FMT_RGB32, SWS_BICUBIC, 0, 0, 0); - if (!scale) { - hal_info_c("%s: ERROR setting up SWS context\n", __func__); - return ret; - } - AVFrame *sframe = av_frame_alloc(); - AVFrame *dframe = av_frame_alloc(); - if (sframe && dframe) { - len = av_image_fill_arrays(sframe->data, sframe->linesize, &(src)[0], sfmt, sw, sh, 1); - if(len>-1) - ret = true; - - if(ret && (len = av_image_fill_arrays(dframe->data, dframe->linesize, &(dst)[0], AV_PIX_FMT_RGB32, dw, dh, 1)<0)) - ret = false; - - if(ret && (len = sws_scale(scale, sframe->data, sframe->linesize, 0, sh, dframe->data, dframe->linesize)<0)) - ret = false; - else - ret = true; - }else{ - hal_info_c("%s: could not alloc sframe (%p) or dframe (%p)\n", __func__, sframe, dframe); - ret = false; - } - - if(sframe){ - av_frame_free(&sframe); - sframe = NULL; - } - if(dframe){ - av_frame_free(&dframe); - dframe = NULL; - } - if(scale){ - sws_freeContext(scale); - scale = NULL; - } - hal_info_c("%s: %s scale %ix%i to %ix%i ,len %i\n",ret?" ":"ERROR",__func__, sw, sh, dw, dh,len); - - return ret; -} - -// grabing the osd picture -void get_osd_size(int &xres, int &yres, int &bits_per_pixel) -{ - int fb=open("/dev/fb/0", O_RDWR); - if (fb == -1) - { - fprintf(stderr, "Framebuffer failed\n"); - return; - } - - struct fb_var_screeninfo var_screeninfo; - if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) - { - fprintf(stderr, "Framebuffer: \n"); - close(fb); - return; - } - close(fb); - - bits_per_pixel = var_screeninfo.bits_per_pixel; - xres=var_screeninfo.xres; - yres=var_screeninfo.yres; - fprintf(stderr, "... Framebuffer-Size: %d x %d\n",xres,yres); - -} -void get_osd_buf(unsigned char *osd_data) -{ - unsigned char *lfb = NULL; - struct fb_fix_screeninfo fix_screeninfo; - struct fb_var_screeninfo var_screeninfo; - - int fb=open("/dev/fb/0", O_RDWR); - if (fb == -1) - { - fprintf(stderr, "Framebuffer failed\n"); - return; - } - - if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) - { - fprintf(stderr, "Framebuffer: \n"); - close(fb); - return; - } - - if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) - { - fprintf(stderr, "Framebuffer: \n"); - close(fb); - return; - } - - if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) - { - fprintf(stderr, "Framebuffer: \n"); - close(fb); - return; - } - - if ( var_screeninfo.bits_per_pixel == 32 ) - { - fprintf(stderr, "Grabbing 32bit Framebuffer ...\n"); - // get 32bit framebuffer - memcpy(osd_data,lfb,fix_screeninfo.line_length*var_screeninfo.yres); - } - close(fb); -} - -inline void rgb24torgb32(unsigned char *src, unsigned char *dest,int picsize) { - for (int i = 0; i < picsize; i++) { - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - *dest++ = 255; - } -} - -/* TODO: aspect ratio correction and PIP */ -bool cVideo::GetScreenImage(unsigned char * &out_data, int &xres, int &yres, bool get_video, bool get_osd, bool scale_to_video) -{ -#define VDEC_PIXFMT AV_PIX_FMT_BGR24 - - hal_info("%s: out_data 0x%p xres %d yres %d vid %d osd %d scale %d\n", - __func__, out_data, xres, yres, get_video, get_osd, scale_to_video); - int aspect = 0; - getPictureInfo(xres, yres, aspect); /* aspect is dummy here */ - aspect = getAspectRatio(); - if(xres < 1 || yres < 1 ) - get_video = false; - - - if(!get_video && !get_osd) - return false; - - int osd_w = 0; - int osd_h = 0; - int bits_per_pixel = 0; - if(get_osd){ - get_osd_size(osd_w, osd_h, bits_per_pixel); - if(osd_w < 1 || osd_h < 1 || bits_per_pixel != 32) - get_osd = false; - if(!scale_to_video && get_osd){ - xres = osd_w; - yres = osd_h; - } - } - unsigned char *osd_data = NULL; - out_data = (unsigned char *)malloc(xres * yres * 4);/* will be freed by caller */ - if (out_data == NULL) - return false; - - if (get_video) { - const int grab_w = 1920; const int grab_h = 1080; //hd51 video0 is always 1920x1080 - unsigned char *video_src = (unsigned char *)malloc(grab_w * grab_h * 3); - if (video_src == NULL) - return false; - if(getvideo2(video_src, grab_w,grab_h) == false){ - free(out_data); - free(video_src); - return false; - } - if (grab_w != xres || grab_h != yres){ /* scale video into data... */ - bool ret = swscale(video_src, out_data, grab_w, grab_h, xres, yres,VDEC_PIXFMT); - if(!ret){ - free(out_data); - free(video_src); - return false; - } - }else{ /* get_video and no fancy scaling needed */ - rgb24torgb32(video_src, out_data, grab_w * grab_h); - } - free(video_src); - } - - if(get_osd){ - osd_data = (unsigned char *)malloc(osd_w * osd_h * 4); - if(osd_data) - get_osd_buf(osd_data); - } - - if (get_osd && (osd_w != xres || osd_h != yres)) { - /* rescale osd */ - unsigned char *osd_src = (unsigned char *)malloc(xres * yres * 4); - if(osd_src){ - bool ret = swscale(osd_data, osd_src, osd_w, osd_h, xres, yres,AV_PIX_FMT_RGB32); - if(!ret){ - free(out_data); - free(osd_data); - free(osd_src); - return false; - } - free(osd_data); - osd_data = NULL; - osd_data = osd_src; - }else{ - free(out_data); - free(osd_data); - return false; - } - } - - if (get_video && get_osd) { - /* alpha blend osd onto out_data (video). TODO: maybe libavcodec can do this? */ - uint32_t *d = (uint32_t *)out_data; - uint32_t *pixpos = (uint32_t *) osd_data; - for (int count = 0; count < yres; count++) { - for (int count2 = 0; count2 < xres; count2++ ) { - uint32_t pix = *pixpos; - if ((pix & 0xff000000) == 0xff000000) - *d = pix; - else { - uint8_t *in = (uint8_t *)(pixpos); - uint8_t *out = (uint8_t *)d; - int a = in[3]; /* TODO: big/little endian? */ - *out = (*out + ((*in - *out) * a) / 256); - in++; out++; - *out = (*out + ((*in - *out) * a) / 256); - in++; out++; - *out = (*out + ((*in - *out) * a) / 256); - } - d++; - pixpos++; - } - } - } - else if (get_osd) /* only get_osd, out_data is not yet populated */ - memcpy(out_data, osd_data, xres * yres * sizeof(uint32_t)); - - if(osd_data) - free(osd_data); - - return true; -} - -bool cVideo::SetCECMode(VIDEO_HDMI_CEC_MODE _deviceType) -{ - return hdmi_cec::getInstance()->SetCECMode(_deviceType); -} - -void cVideo::SetCECAutoStandby(bool state) -{ - hdmi_cec::getInstance()->SetCECAutoStandby(state); -} - -void cVideo::SetCECAutoView(bool state) -{ - hdmi_cec::getInstance()->SetCECAutoView(state); -} - -int cVideo::GetAudioDestination() -{ - return (int)hdmi_cec::getInstance()->GetAudioDestination(); -} - -void cVideo::SetAudioDestination(int audio_dest) -{ - hdmi_cec::getInstance()->SetAudioDestination(audio_dest); -} \ No newline at end of file diff --git a/libmipsbox/video.cpp b/libmipsbox/video.cpp new file mode 120000 index 0000000..5ee7b52 --- /dev/null +++ b/libmipsbox/video.cpp @@ -0,0 +1 @@ +../libarmbox/video.cpp \ No newline at end of file diff --git a/libmipsbox/video_lib.h b/libmipsbox/video_lib.h deleted file mode 100644 index 40ae0fd..0000000 --- a/libmipsbox/video_lib.h +++ /dev/null @@ -1,263 +0,0 @@ -#ifndef __VIDEO_LIB_H__ -#define __VIDEO_LIB_H__ - -#include -#include "cs_types.h" -#include "dmx_hal.h" - -typedef struct cs_vs_format_t -{ - char format[16]; -} cs_vs_format_struct_t; - -typedef enum { - ANALOG_SD_RGB_CINCH = 0x00, - ANALOG_SD_YPRPB_CINCH, - ANALOG_HD_RGB_CINCH, - ANALOG_HD_YPRPB_CINCH, - ANALOG_SD_RGB_SCART = 0x10, - ANALOG_SD_YPRPB_SCART, - ANALOG_HD_RGB_SCART, - ANALOG_HD_YPRPB_SCART, - ANALOG_SCART_MASK = 0x10 -} analog_mode_t; - -typedef enum { - COLORFORMAT_RGB = 0x10, // keep compatible with analog_mode_t - COLORFORMAT_YUV, - COLORFORMAT_CVBS, - COLORFORMAT_SVIDEO, - COLORFORMAT_HDMI_AUTO, - COLORFORMAT_HDMI_RGB, - COLORFORMAT_HDMI_YCBCR444, - COLORFORMAT_HDMI_YCBCR422, - COLORFORMAT_HDMI_YCBCR420 -} COLOR_FORMAT; - -typedef enum { - VIDEO_FORMAT_MPEG2 = 0, - VIDEO_FORMAT_MPEG4_H264, - VIDEO_FORMAT_VC1, - VIDEO_FORMAT_JPEG, - VIDEO_FORMAT_GIF, - VIDEO_FORMAT_PNG, - VIDEO_FORMAT_MPEG4_H265, - VIDEO_FORMAT_AVS = 16 -} VIDEO_FORMAT; - -typedef enum { - VIDEO_SD = 0, - VIDEO_HD, - VIDEO_120x60i, - VIDEO_320x240i, - VIDEO_1440x800i, - VIDEO_360x288i -} VIDEO_DEFINITION; - -typedef enum { - VIDEO_FRAME_RATE_23_976 = 0, - VIDEO_FRAME_RATE_24, - VIDEO_FRAME_RATE_25, - VIDEO_FRAME_RATE_29_97, - VIDEO_FRAME_RATE_30, - VIDEO_FRAME_RATE_50, - VIDEO_FRAME_RATE_59_94, - VIDEO_FRAME_RATE_60 -} VIDEO_FRAME_RATE; - -typedef enum { - DISPLAY_AR_1_1, - DISPLAY_AR_4_3, - DISPLAY_AR_14_9, - DISPLAY_AR_16_9, - DISPLAY_AR_20_9, - DISPLAY_AR_RAW -} DISPLAY_AR; - -typedef enum { - DISPLAY_AR_MODE_PANSCAN = 0, - DISPLAY_AR_MODE_LETTERBOX, - DISPLAY_AR_MODE_NONE, - DISPLAY_AR_MODE_PANSCAN2 -} DISPLAY_AR_MODE; - -typedef enum { - VIDEO_DB_DR_NEITHER = 0, - VIDEO_DB_ON, - VIDEO_DB_DR_BOTH -} VIDEO_DB_DR; - -typedef enum { - VIDEO_PLAY_STILL = 0, - VIDEO_PLAY_CLIP, - VIDEO_PLAY_TRICK, - VIDEO_PLAY_MOTION, - VIDEO_PLAY_MOTION_NO_SYNC -} VIDEO_PLAY_MODE; - -typedef enum { - VIDEO_STD_NTSC, - VIDEO_STD_SECAM, - VIDEO_STD_PAL, - VIDEO_STD_480P, - VIDEO_STD_576P, - VIDEO_STD_720P60, - VIDEO_STD_1080I60, - VIDEO_STD_720P50, - VIDEO_STD_1080I50, - VIDEO_STD_1080P30, - VIDEO_STD_1080P24, - VIDEO_STD_1080P25, - VIDEO_STD_1080P50, - VIDEO_STD_1080P60, - VIDEO_STD_1080P2397, - VIDEO_STD_1080P2997, - VIDEO_STD_2160P24, - VIDEO_STD_2160P25, - VIDEO_STD_2160P30, - VIDEO_STD_2160P50, - VIDEO_STD_AUTO, - VIDEO_STD_MAX = VIDEO_STD_AUTO -} VIDEO_STD; - -typedef enum { - VIDEO_HDMI_CEC_MODE_OFF = 0, - VIDEO_HDMI_CEC_MODE_TUNER = 3, - VIDEO_HDMI_CEC_MODE_RECORDER = 1 -} VIDEO_HDMI_CEC_MODE; - -typedef enum { - VIDEO_HDMI_CEC_VOL_OFF = 0, - VIDEO_HDMI_CEC_VOL_AUDIOSYSTEM = 1, - VIDEO_HDMI_CEC_VOL_TV = 2 -} VIDEO_HDMI_CEC_VOL; - -typedef enum -{ - VIDEO_CONTROL_BRIGHTNESS = 0, - VIDEO_CONTROL_CONTRAST, - VIDEO_CONTROL_SATURATION, - VIDEO_CONTROL_HUE, - VIDEO_CONTROL_SHARPNESS, - VIDEO_CONTROL_BLOCK_NOISE_REDUCTION, - VIDEO_CONTROL_MOSQUITO_NOISE_REDUCTION, - VIDEO_CONTROL_DIGITAL_CONTOUR_REMOVAL, - VIDEO_CONTROL_AUTO_FLESH, - VIDEO_CONTROL_GREEN_BOOST, - VIDEO_CONTROL_BLUE_BOOST, - VIDEO_CONTROL_DYNAMIC_CONTRAST, - VIDEO_CONTROL_SCALER_SHARPNESS, - VIDEO_CONTROL_ZAPPING_MODE, - VIDEO_CONTROL_MAX = VIDEO_CONTROL_SHARPNESS -} VIDEO_CONTROL; - -class cDemux; -class cPlayback; - -class cVideo -{ - friend class cPlayback; - friend class cDemux; - private: - /* video device */ - int fd; - unsigned int devnum; - /* apparently we cannot query the driver's state - => remember it */ - video_play_state_t playstate; - int /*vidDispMode_t*/ croppingMode; - int /*vidOutFmt_t*/ outputformat; - - VIDEO_FORMAT StreamType; - VIDEO_DEFINITION VideoDefinition; - DISPLAY_AR DisplayAR; - VIDEO_PLAY_MODE SyncMode; - DISPLAY_AR_MODE ARMode; - VIDEO_DB_DR eDbDr; - DISPLAY_AR PictureAR; - VIDEO_FRAME_RATE FrameRate; - int video_standby; - int brightness; - int contrast; - int saturation; - int hue; - int sharpness; - int block_noise_reduction; - int mosquito_noise_reduction; - int digital_contour_removal; - int auto_flesh; - int green_boost; - int blue_boost; - int dynamic_contrast; - int scaler_sharpness; - int zapping_mode; - int blank_mode; - - /* used internally by dmx */ - int64_t GetPTS(void); - - public: - /* constructor & destructor */ - cVideo(int mode, void *, void *, unsigned int unit = 0); - ~cVideo(void); - - /* used internally by playback */ - void openDevice(void); - void closeDevice(void); - - void * GetTVEnc() { return NULL; }; - void * GetTVEncSD() { return NULL; }; - - /* aspect ratio */ - int getAspectRatio(void); - void getPictureInfo(int &width, int &height, int &rate); - int setAspectRatio(int aspect, int mode); - - /* cropping mode */ - int setCroppingMode(int x = 0 /*vidDispMode_t x = VID_DISPMODE_NORM*/); - - /* get play state */ - int getPlayState(void); - - /* blank on freeze */ - int getBlank(void); - int setBlank(int enable); - - /* change video play state. Parameters are all unused. */ - int Start(void *PcrChannel = NULL, unsigned short PcrPid = 0, unsigned short VideoPid = 0, void *x = NULL); - int Stop(bool blank = true); - bool Pause(void); - - /* get video system infos */ - int GetVideoSystem(void); - /* when system = -1 then use current video system */ - void GetVideoSystemFormatName(cs_vs_format_t* format, int system); - - /* set video_system */ - int SetVideoSystem(int video_system, bool remember = true); - int SetStreamType(VIDEO_FORMAT type); - void SetSyncMode(AVSYNC_TYPE mode); - bool SetCECMode(VIDEO_HDMI_CEC_MODE); - void SetCECAutoView(bool); - void SetCECAutoStandby(bool); - int GetAudioDestination(); - void SetAudioDestination(int audio_dest); - void StopPicture(); - void Standby(unsigned int bOn); - void Pig(int x, int y, int w, int h, int osd_w = 1064, int osd_h = 600, int startx = 0, int starty = 0, int endx = 1279, int endy = 719); - void SetControl(int, int); - void setContrast(int val); - void SetVideoMode(analog_mode_t mode); - void SetDBDR(int) { return; }; - void SetAudioHandle(void *) { return; }; - void SetAutoModes(int [VIDEO_STD_MAX]) { return; }; - int OpenVBI(int) { return 0; }; - int CloseVBI(void) { return 0; }; - int StartVBI(unsigned short) { return 0; }; - int StopVBI(void) { return 0; }; - void SetDemux(cDemux *dmx); - void SetColorFormat(COLOR_FORMAT color_format); - bool GetScreenImage(unsigned char * &data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); -}; - -#endif // __VIDEO_LIB_H__ diff --git a/libmipsbox/video_lib.h b/libmipsbox/video_lib.h new file mode 120000 index 0000000..21a9fa2 --- /dev/null +++ b/libmipsbox/video_lib.h @@ -0,0 +1 @@ +../libarmbox/video_lib.h \ No newline at end of file