[Redbutton-devel] SF.net SVN: redbutton: [22] redbutton-browser/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2006-03-18 09:57:03
|
Revision: 22 Author: skilvington Date: 2006-03-18 01:56:46 -0800 (Sat, 18 Mar 2006) ViewCVS: http://svn.sourceforge.net/redbutton/?rev=22&view=rev Log Message: ----------- return audio/video PIDs to stream player Modified Paths: -------------- redbutton-browser/trunk/MHEGBackend.c redbutton-browser/trunk/MHEGBackend.h redbutton-browser/trunk/MHEGEngine.c redbutton-browser/trunk/MHEGEngine.h redbutton-browser/trunk/MHEGStreamPlayer.c redbutton-browser/trunk/MHEGStreamPlayer.h Modified: redbutton-browser/trunk/MHEGBackend.c =================================================================== --- redbutton-browser/trunk/MHEGBackend.c 2006-03-15 16:03:26 UTC (rev 21) +++ redbutton-browser/trunk/MHEGBackend.c 2006-03-18 09:56:46 UTC (rev 22) @@ -17,7 +17,7 @@ bool local_checkContentRef(MHEGBackend *, ContentReference *); bool local_loadFile(MHEGBackend *, OctetString *, OctetString *); FILE *local_openFile(MHEGBackend *, OctetString *); -FILE *local_openStream(MHEGBackend *, bool, int, bool, int); +FILE *local_openStream(MHEGBackend *, bool, int *, bool, int *); static struct MHEGBackendFns local_backend_fns = { @@ -31,7 +31,7 @@ bool remote_checkContentRef(MHEGBackend *, ContentReference *); bool remote_loadFile(MHEGBackend *, OctetString *, OctetString *); FILE *remote_openFile(MHEGBackend *, OctetString *); -FILE *remote_openStream(MHEGBackend *, bool, int, bool, int); +FILE *remote_openStream(MHEGBackend *, bool, int *, bool, int *); static struct MHEGBackendFns remote_backend_fns = { @@ -305,13 +305,14 @@ /* * 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 + * 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 + * updates *audio_tag and/or *video_tag to the actual PIDs in the Transport Stream * returns NULL on error */ FILE * -local_openStream(MHEGBackend *t, bool have_audio, int audio_tag, bool have_video, int video_tag) +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 @@ -456,40 +457,67 @@ /* * 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 + * 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 + * updates *audio_tag and/or *video_tag to the actual PIDs in the Transport Stream * returns NULL on error */ FILE * -remote_openStream(MHEGBackend *t, bool have_audio, int audio_tag, bool have_video, int video_tag) +remote_openStream(MHEGBackend *t, bool have_audio, int *audio_tag, bool have_video, int *video_tag) { char cmd[PATH_MAX]; FILE *sock; + char pids[128]; + unsigned int audio_pid = 0; + unsigned int video_pid = 0; + bool err; /* 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); + 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); + snprintf(cmd, sizeof(cmd), "astream %d\n", *audio_tag); /* video only */ else - snprintf(cmd, sizeof(cmd), "vstream %d\n", video_tag); + 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) + if(remote_response(sock) != BACKEND_RESPONSE_OK + || fgets(pids, sizeof(pids), sock) == NULL) { fclose(sock); sock = NULL; } + /* update the PID variables */ + if(have_audio && have_video) + err = (sscanf(pids, "AudioPID %u VideoPID %u", &audio_pid, &video_pid) != 2); + else if(have_audio) + err = (sscanf(pids, "AudioPID %u", &audio_pid) != 1); + else + err = (sscanf(pids, "VideoPID %u", &video_pid) != 1); + + if(!err) + { + if(have_audio) + *audio_tag = audio_pid; + if(have_video) + *video_tag = video_pid; + } + else + { + fclose(sock); + sock = NULL; + } + return sock; } Modified: redbutton-browser/trunk/MHEGBackend.h =================================================================== --- redbutton-browser/trunk/MHEGBackend.h 2006-03-15 16:03:26 UTC (rev 21) +++ redbutton-browser/trunk/MHEGBackend.h 2006-03-18 09:56:46 UTC (rev 22) @@ -22,7 +22,7 @@ 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 */ + 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-15 16:03:26 UTC (rev 21) +++ redbutton-browser/trunk/MHEGEngine.c 2006-03-18 09:56:46 UTC (rev 22) @@ -1331,6 +1331,21 @@ } /* + * 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 + * updates *audio_tag and/or *video_tag to the actual PIDs in the Transport Stream + * returns NULL on error + */ + +FILE * +MHEGEngine_openStream(bool have_audio, int *audio_tag, bool have_video, int *video_tag) +{ + return (*(engine.backend.fns->openStream))(&engine.backend, have_audio, audio_tag, have_video, video_tag); +} + +/* * returns the absolute group ID, ie it always starts with "~//" * returns a ptr to static string that will be overwritten by the next call to this routine * section 8.3.2 of the UK MHEG Profile says the filename prefixes are: Modified: redbutton-browser/trunk/MHEGEngine.h =================================================================== --- redbutton-browser/trunk/MHEGEngine.h 2006-03-15 16:03:26 UTC (rev 21) +++ redbutton-browser/trunk/MHEGEngine.h 2006-03-18 09:56:46 UTC (rev 22) @@ -221,6 +221,7 @@ bool MHEGEngine_checkContentRef(ContentReference *); bool MHEGEngine_loadFile(OctetString *, OctetString *); FILE *MHEGEngine_openFile(OctetString *); +FILE *MHEGEngine_openStream(bool, int *, bool, int *); char *MHEGEngine_absoluteFilename(OctetString *); Modified: redbutton-browser/trunk/MHEGStreamPlayer.c =================================================================== --- redbutton-browser/trunk/MHEGStreamPlayer.c 2006-03-15 16:03:26 UTC (rev 21) +++ redbutton-browser/trunk/MHEGStreamPlayer.c 2006-03-18 09:56:46 UTC (rev 22) @@ -5,6 +5,7 @@ #include <string.h> #include <stdio.h> +#include "MHEGEngine.h" #include "MHEGStreamPlayer.h" #include "utils.h" @@ -35,6 +36,7 @@ p->have_video = true; p->video_tag = tag; + p->video_pid = -1; return; } @@ -47,6 +49,7 @@ p->have_audio = true; p->audio_tag = tag; + p->audio_pid = -1; return; } @@ -54,10 +57,14 @@ void MHEGStreamPlayer_play(MHEGStreamPlayer *p) { + verbose("MHEGStreamPlayer_play: audio_tag=%d video_tag=%d", p->audio_tag, p->video_tag); + + p->audio_pid = p->audio_tag; + p->video_pid = p->video_tag; +// if((p->ts = MHEGEngine_openStream(p->have_audio, &p->audio_pid, p->have_video, &p->video_pid)) == NULL) +// error("Unable to open MPEG stream"); /* TODO */ printf("TODO: MHEGStreamPlayer_play: not yet implemented\n"); -if(p->have_audio) printf("TODO: audio tag=%d\n", p->audio_tag); -if(p->have_video) printf("TODO: video tag=%d\n", p->video_tag); return; } @@ -65,9 +72,11 @@ void MHEGStreamPlayer_stop(MHEGStreamPlayer *p) { -/* TODO */ -printf("TODO: MHEGStreamPlayer_stop: not yet implemented\n"); + verbose("MHEGStreamPlayer_stop"); + if(p->ts != NULL) + fclose(p->ts); + return; } Modified: redbutton-browser/trunk/MHEGStreamPlayer.h =================================================================== --- redbutton-browser/trunk/MHEGStreamPlayer.h 2006-03-15 16:03:26 UTC (rev 21) +++ redbutton-browser/trunk/MHEGStreamPlayer.h 2006-03-18 09:56:46 UTC (rev 22) @@ -13,6 +13,9 @@ bool have_audio; /* false if we have no audio stream */ int video_tag; /* video stream component tag (-1 => default for current service ID) */ int audio_tag; /* audio stream component tag (-1 => default for current service ID) */ + int video_pid; /* PID in MPEG Transport Stream (-1 => not yet known) */ + int audio_pid; /* PID in MPEG Transport Stream (-1 => not yet known) */ + FILE *ts; /* MPEG Transport Stream */ } MHEGStreamPlayer; void MHEGStreamPlayer_init(MHEGStreamPlayer *); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |