📄 eyetvplugin.c
字号:
/****************************************************************************** eyetvplugin.c: Plug-In for the EyeTV software to connect to VLC****************************************************************************** Copyright (C) 2006-2007 the VideoLAN team* $Id$** Authors: Felix Kühne <fkuehne at videolan dot org>** 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, write to the Free Software* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.*****************************************************************************/#include "eyetvplugin.h"#include <sys/types.h>#include <sys/socket.h>#include <sys/un.h>#include <unistd.h>#include <fcntl.h>#define MAX_PIDS 256#define MAX_ACTIVE_PIDS 256#define MAX_DEVICES 16#define VLC_NOTIFICATION_OBJECT "VLCEyeTVSupport"#pragma push#pragma pack(1)/* Structure for TS-Packets */typedef struct { uint32_t sync_byte : 8, transport_error_indicator : 1, payload_unit_start_indicator : 1, transport_priority : 1, PID : 13, transport_scrambling_control : 2, adaptation_field_control : 2, continuity_counter : 4; uint8_t payload[184];} TransportStreamPacket;#pragma pop/* Structure to hold global data to communicate with EyeTV */typedef struct { EyeTVPluginCallbackProc callback; /* Structure to hold current active service */ EyeTVPluginDeviceID activeDeviceID; long activePIDsCount; EyeTVPluginPIDInfo activePIDs[MAX_ACTIVE_PIDS];} VLCEyeTVPluginGlobals_t;/* following globals limits us to one VLC instance using EyeTV */static int i_deviceCount;static int i_vlcSock;#pragma mark -/* initialise the plug-in */static long VLCEyeTVPluginInitialize(VLCEyeTVPluginGlobals_t** globals, long apiVersion, EyeTVPluginCallbackProc callback){ printf("VLC media player Plug-In: Initialize\n"); long result = 0; /* init our own storage */ i_deviceCount = 0; i_vlcSock = -1; /* notify a potential VLC instance about our initialisation */ CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter(), CFSTR("PluginInit"), CFSTR(VLC_NOTIFICATION_OBJECT), /*userInfo*/ NULL, TRUE ); /* init our notification support */ CFNotificationCenterAddObserver( CFNotificationCenterGetDistributedCenter(), /* observer */ NULL, /* callBack */ VLCEyeTVPluginGlobalNotificationReceived, /* name, NULL==all */ NULL, CFSTR(VLC_NOTIFICATION_OBJECT), CFNotificationSuspensionBehaviorDeliverImmediately ); *globals = (VLCEyeTVPluginGlobals_t *) calloc(1, sizeof( VLCEyeTVPluginGlobals_t ) ); ( *globals )->callback = callback; return result;}/* we will be terminated soon, clean up */static long VLCEyeTVPluginTerminate(VLCEyeTVPluginGlobals_t *globals){ long result = 0; printf("VLC media player Plug-In: Terminate\n"); /* notify a potential VLC instance about our termination */ CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter (), CFSTR("PluginQuit"), CFSTR(VLC_NOTIFICATION_OBJECT), /*userInfo*/ NULL, TRUE ); /* remove us from the global notification centre */ CFNotificationCenterRemoveEveryObserver( CFNotificationCenterGetDistributedCenter(), (void *)VLCEyeTVPluginGlobalNotificationReceived ); /* close data connection */ if( i_vlcSock != -1 ) { close( i_vlcSock ); i_vlcSock = -1; } free( globals ); return result;}/* called when EyeTV asks various stuff about us */static long VLCEyeTVPluginGetInformation(VLCEyeTVPluginGlobals_t *globals, long* outAPIVersion, char* outName, char *outDescription){ printf("VLC media player Plug-In: GetInfo\n"); long result = 0; if( globals ) { if( outAPIVersion ) { *outAPIVersion = EYETV_PLUGIN_API_VERSION; } if( outName ) { strcpy( outName, "VLC media player Plug-In"); } if( outDescription ) { strcpy( outDescription, "This Plug-In connects EyeTV to the VLC media player for streaming purposes."); } } return result;}/* called if we received a global notification */void VLCEyeTVPluginGlobalNotificationReceived( CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo ){ /* when VLC launches after us, we need to inform it about our existance and the current state of available devices */ if( CFStringCompare( name, CFSTR( "VLCOSXGUIInit" ), 0) == kCFCompareEqualTo ) { /* we're here */ CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter (), CFSTR("PluginInit"), CFSTR(VLC_NOTIFICATION_OBJECT), /*userInfo*/ NULL, TRUE ); if( i_deviceCount > 0 ) { /* at least one device is apparently connected */ CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter (), CFSTR("DeviceAdded"), CFSTR(VLC_NOTIFICATION_OBJECT), /*userInfo*/ NULL, TRUE ); } } /* VLC wants us to start sending data */ if( CFStringCompare( name, CFSTR( "VLCAccessStartDataSending" ), 0) == kCFCompareEqualTo ) { if( i_vlcSock == -1 ) { int peerSock; /* set-up data socket */ peerSock = socket(AF_UNIX, SOCK_STREAM, 0); if( peerSock != -1 ) { struct sockaddr_un peerAddr; /* set-up connection address */ memset(&peerAddr, 0, sizeof(peerAddr)); peerAddr.sun_family = AF_UNIX; strncpy(peerAddr.sun_path, "/tmp/.vlc-eyetv-bridge", sizeof(peerAddr.sun_path)-1); /* connect */ printf("data connect in progess...\n"); if( connect(peerSock, (struct sockaddr *)&peerAddr, sizeof(struct sockaddr_un)) != -1 ) { printf("data sending switched on\n"); i_vlcSock = peerSock; } else printf("connect data socket failed (errno=%d)\n", errno ); } else printf("create data socket failed (errno=%d)\n", errno ); } } /* VLC wants us to stop sending data */ if( CFStringCompare( name, CFSTR( "VLCAccessStopDataSending" ), 0) == kCFCompareEqualTo ) { if( i_vlcSock != -1 ) { close( i_vlcSock ); i_vlcSock = -1; printf( "data sending switched off\n" ); } }}/* called if a device is added */static long VLCEyeTVPluginDeviceAdded(VLCEyeTVPluginGlobals_t *globals, EyeTVPluginDeviceID deviceID, EyeTVPluginDeviceType deviceType){ printf("VLC media player Plug-In: Device with type %i and ID %i added\n", (int)deviceType, (int)deviceID); long result = 0; if( globals ) { ++i_deviceCount; if( 1 == i_deviceCount ) { /* notify a potential VLC instance about the addition */ CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter(), CFSTR("DeviceAdded"), CFSTR(VLC_NOTIFICATION_OBJECT), /*userInfo*/ NULL, TRUE ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -