[Redbutton-devel] SF.net SVN: redbutton: [15] redbutton-browser/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2006-03-03 16:51:28
|
Revision: 15 Author: skilvington Date: 2006-03-03 08:51:20 -0800 (Fri, 03 Mar 2006) ViewCVS: http://svn.sourceforge.net/redbutton/?rev=15&view=rev Log Message: ----------- add openStream() to frontend Modified Paths: -------------- redbutton-browser/trunk/MHEGApp.c redbutton-browser/trunk/MHEGBackend.c redbutton-browser/trunk/MHEGBackend.h redbutton-browser/trunk/MHEGEngine.c redbutton-browser/trunk/MHEGEngine.h Modified: redbutton-browser/trunk/MHEGApp.c =================================================================== --- redbutton-browser/trunk/MHEGApp.c 2006-03-03 13:45:56 UTC (rev 14) +++ redbutton-browser/trunk/MHEGApp.c 2006-03-03 16:51:20 UTC (rev 15) @@ -61,7 +61,7 @@ m->app = safe_malloc(sizeof(InterchangedObject)); bzero(m->app, sizeof(InterchangedObject)); - if((der = MHEGEngine_openFile(derfile, "r")) == NULL) + if((der = MHEGEngine_openFile(derfile)) == NULL) { error("Unable to open '%.*s'", derfile->size, derfile->data); safe_free(m->app); @@ -116,7 +116,7 @@ m->scene = safe_malloc(sizeof(InterchangedObject)); bzero(m->scene, sizeof(InterchangedObject)); - if((der = MHEGEngine_openFile(derfile, "r")) == NULL) + if((der = MHEGEngine_openFile(derfile)) == NULL) { error("Unable to open '%.*s'", derfile->size, derfile->data); safe_free(m->scene); Modified: redbutton-browser/trunk/MHEGBackend.c =================================================================== --- redbutton-browser/trunk/MHEGBackend.c 2006-03-03 13:45:56 UTC (rev 14) +++ redbutton-browser/trunk/MHEGBackend.c 2006-03-03 16:51:20 UTC (rev 15) @@ -16,25 +16,29 @@ /* local backend funcs */ bool local_checkContentRef(MHEGBackend *, ContentReference *); bool local_loadFile(MHEGBackend *, OctetString *, OctetString *); -FILE *local_openFile(MHEGBackend *, OctetString *, char *); +FILE *local_openFile(MHEGBackend *, OctetString *); +FILE *local_openStream(MHEGBackend *, bool, int, bool, int); static struct MHEGBackendFns local_backend_fns = { local_checkContentRef, /* checkContentRef */ local_loadFile, /* loadFile */ local_openFile, /* openFile */ + local_openStream, /* openStream */ }; /* remote backend funcs */ bool remote_checkContentRef(MHEGBackend *, ContentReference *); bool remote_loadFile(MHEGBackend *, OctetString *, OctetString *); -FILE *remote_openFile(MHEGBackend *, OctetString *, char *); +FILE *remote_openFile(MHEGBackend *, OctetString *); +FILE *remote_openStream(MHEGBackend *, bool, int, bool, int); static struct MHEGBackendFns remote_backend_fns = { remote_checkContentRef, /* checkContentRef */ remote_loadFile, /* loadFile */ remote_openFile, /* openFile */ + remote_openStream, /* openStream */ }; /* internal functions */ @@ -283,15 +287,42 @@ return (out->data != NULL); } +/* + * return a read-only FILE handle for the given carousel file + * returns NULL on error + */ + FILE * -local_openFile(MHEGBackend *t, OctetString *name, char *mode) +local_openFile(MHEGBackend *t, OctetString *name) { char *external = external_filename(t, name); - return fopen(external, mode); + return fopen(external, "r"); } /* + * return a read-only FILE handle for an MPEG Transport Stream + * the TS will contain an audio stream (if have_audio is true) and a video stream (if have_video is true) + * the audio_tag and video_tag numbers refer to Component/Association Tag values from the DVB PMT + * if audio_tag or video_tag is -1, the default audio and/or video stream for the current Service ID is used + * returns NULL on error + */ + +FILE * +local_openStream(MHEGBackend *t, bool have_audio, int audio_tag, bool have_video, int video_tag) +{ + /* + * we need to convert the audio/video_tag into PIDs + * we could either: + * 1. parse the PMT ourselves, and open the DVB device ourselves + * 2. have a backend command to convert Component Tags to PIDs, then open the DVB device ourselves + * 3. just stream the TS from the backend + * we choose 3, to avoid duplicating code and having to pass "-d <device>" options etc + */ + return remote_openStream(t, have_audio, audio_tag, have_video, video_tag); +} + +/* * remote routines */ @@ -366,8 +397,13 @@ return success; } +/* + * return a read-only FILE handle for the given carousel file + * returns NULL on error + */ + FILE * -remote_openFile(MHEGBackend *t, OctetString *name, char *mode) +remote_openFile(MHEGBackend *t, OctetString *name) { char cmd[PATH_MAX]; FILE *sock; @@ -415,3 +451,43 @@ return out; } +/* + * return a read-only FILE handle for an MPEG Transport Stream + * the TS will contain an audio stream (if have_audio is true) and a video stream (if have_video is true) + * the audio_tag and video_tag numbers refer to Component/Association Tag values from the DVB PMT + * if audio_tag or video_tag is -1, the default audio and/or video stream for the current Service ID is used + * returns NULL on error + */ + +FILE * +remote_openStream(MHEGBackend *t, bool have_audio, int audio_tag, bool have_video, int video_tag) +{ + char cmd[PATH_MAX]; + FILE *sock; + + /* no PIDs required */ + if(!have_audio && !have_video) + return NULL; + /* video and audio */ + else if(have_audio && have_video) + snprintf(cmd, sizeof(cmd), "avstream %d %d\n", audio_tag, video_tag); + /* audio only */ + else if(have_audio) + snprintf(cmd, sizeof(cmd), "astream %d\n", audio_tag); + /* video only */ + else + snprintf(cmd, sizeof(cmd), "vstream %d\n", video_tag); + + if((sock = remote_command(t, cmd)) == NULL) + return NULL; + + /* did it work */ + if(remote_response(sock) != BACKEND_RESPONSE_OK) + { + fclose(sock); + sock = NULL; + } + + return sock; +} + Modified: redbutton-browser/trunk/MHEGBackend.h =================================================================== --- redbutton-browser/trunk/MHEGBackend.h 2006-03-03 13:45:56 UTC (rev 14) +++ redbutton-browser/trunk/MHEGBackend.h 2006-03-03 16:51:20 UTC (rev 15) @@ -19,9 +19,10 @@ /* function pointers */ struct MHEGBackendFns { - bool (*checkContentRef)(struct MHEGBackend *, ContentReference *); /* check a file exists */ - bool (*loadFile)(struct MHEGBackend *, OctetString *, OctetString *); /* load a file */ - FILE *(*openFile)(struct MHEGBackend *, OctetString *, char *); /* open a file */ + bool (*checkContentRef)(struct MHEGBackend *, ContentReference *); /* check a carousel file exists */ + bool (*loadFile)(struct MHEGBackend *, OctetString *, OctetString *); /* load a carousel file */ + FILE *(*openFile)(struct MHEGBackend *, OctetString *); /* open a carousel file */ + FILE *(*openStream)(struct MHEGBackend *, bool, int, bool, int); /* open an MPEG Transport Stream */ } *fns; } MHEGBackend; Modified: redbutton-browser/trunk/MHEGEngine.c =================================================================== --- redbutton-browser/trunk/MHEGEngine.c 2006-03-03 13:45:56 UTC (rev 14) +++ redbutton-browser/trunk/MHEGEngine.c 2006-03-03 16:51:20 UTC (rev 15) @@ -1320,15 +1320,14 @@ } /* - * returns a FILE handle for the given carousel file - * mode is an fopen() mode, ie "r", "w", etc + * returns a read-only FILE handle for the given carousel file * returns NULL on error */ FILE * -MHEGEngine_openFile(OctetString *name, char *mode) +MHEGEngine_openFile(OctetString *name) { - return (*(engine.backend.fns->openFile))(&engine.backend, name, mode); + return (*(engine.backend.fns->openFile))(&engine.backend, name); } /* Modified: redbutton-browser/trunk/MHEGEngine.h =================================================================== --- redbutton-browser/trunk/MHEGEngine.h 2006-03-03 13:45:56 UTC (rev 14) +++ redbutton-browser/trunk/MHEGEngine.h 2006-03-03 16:51:20 UTC (rev 15) @@ -220,7 +220,7 @@ bool MHEGEngine_checkContentRef(ContentReference *); bool MHEGEngine_loadFile(OctetString *, OctetString *); -FILE *MHEGEngine_openFile(OctetString *, char *); +FILE *MHEGEngine_openFile(OctetString *); char *MHEGEngine_absoluteFilename(OctetString *); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |