annotate libmpdemux/demux_pva.c @ 7364:b2445802532c

.PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer slightly modified patch, original by Matteo Giani <matgiani@ctonet.it>
author arpi
date Tue, 10 Sep 2002 21:50:03 +0000
parents
children c4434bdf6e51
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7364
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
1 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
2 * demuxer for PVA files, such as the ones produced by software to manage DVB boards
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
3 * like the Hauppauge WinTV DVBs, for MPlayer.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
4 *
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
5 * Uses info from the PVA file specifications found at
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
6 *
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
7 * http://www.technotrend.de/download/av_format_v1.pdf
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
8 *
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
9 * Known issue:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
10 * - Does not seem to correctly demux files produced by MultiDec (on some channels).
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
11 * They seem not to be correctly formatted. In fact, other DVB software which uses
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
12 * the DVB board for playback plays them fine, but existing software which should
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
13 * convert PVAs to MPEG-PS streams fails on them as well.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
14 * Feedback would be appreciated.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
15 *
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
16 *
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
17 * written by Matteo Giani
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
18 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
19
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
20
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
21
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
22
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
23 #include "config.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
24 #include "mp_msg.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
25 #include "help_mp.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
26
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
27 #include "stream.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
28 #include "demuxer.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
29 #include "stheader.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
30
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
31 #include "bswap.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
32
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
33 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
34 * #defines below taken from PVA spec (see URL above)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
35 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
36
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
37 #define PVA_MAX_VIDEO_PACK_LEN 6*1024
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
38
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
39 #define VIDEOSTREAM 0x01
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
40 #define MAINAUDIOSTREAM 0x02
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
41
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
42 typedef struct {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
43 unsigned long offset;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
44 long size;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
45 uint8_t type;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
46 uint8_t is_packet_start;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
47 uint64_t pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
48 } pva_payload_t;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
49
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
50
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
51 typedef struct {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
52 float last_audio_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
53 float last_video_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
54 uint8_t just_synced;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
55 uint8_t synced_stream_id;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
56 } pva_priv_t;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
57
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
58
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
59 int pva_sync(demuxer_t * demuxer)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
60 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
61 uint8_t buffer[5]={0,0,0,0,0};
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
62 int count;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
63 pva_priv_t * priv = (pva_priv_t *) demuxer->priv;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
64
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
65 /* This is a hack. Since this function is called both for actual syncing and by
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
66 * pva_check_file to check file type, we must check whether the priv structure has
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
67 * already been allocated, otherwise we will dereference NULL and segfault.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
68 * So, if priv is NULL (not yet allocated) use a local variable, otherwise use priv->just_synced.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
69 * This field is in the priv structure so that pva_get_payload knows that pva_sync has already
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
70 * read (part of) the PVA header. This way we can avoid to seek back and (hopefully) be able to read
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
71 * from pipes and such.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
72 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
73
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
74 uint8_t local_synced=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
75 uint8_t * syncedptr;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
76
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
77 syncedptr=(priv==NULL)?&local_synced:&priv->just_synced;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
78
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
79
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
80 for(count=0 ; count<PVA_MAX_VIDEO_PACK_LEN && !demuxer->stream->eof && !*syncedptr ; count++)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
81 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
82 buffer[0]=buffer[1];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
83 buffer[1]=buffer[2];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
84 buffer[2]=buffer[3];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
85 buffer[3]=buffer[4];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
86 buffer[4]=stream_read_char(demuxer->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
87 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
88 * Check for a PVA packet beginning sequence: we check both the "AV" word at the
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
89 * very beginning and the "0x55" reserved byte (which is unused and set to 0x55 by spec)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
90 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
91 if(buffer[0]=='A' && buffer[1] == 'V' && buffer[4] == 0x55) *syncedptr=1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
92 //printf("demux_pva: pva_sync() current offset: %d\n",stream_tell(demuxer->stream));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
93 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
94 if(*syncedptr)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
95 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
96 if(priv!=NULL) priv->synced_stream_id=buffer[2];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
97 return 1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
98 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
99 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
100 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
101 return 0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
102 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
103 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
104
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
105 int pva_check_file(demuxer_t * demuxer)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
106 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
107 uint8_t buffer[5]={0,0,0,0,0};
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
108 mp_msg(MSGT_DEMUX, MSGL_V, "Checking for PVA\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
109 stream_read(demuxer->stream,buffer,5);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
110 if(buffer[0]=='A' && buffer[1] == 'V' && buffer[4] == 0x55)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
111 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
112 mp_msg(MSGT_DEMUX,MSGL_DBG2, "Success: PVA\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
113 return 1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
114 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
115 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
116 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
117 mp_msg(MSGT_DEMUX,MSGL_DBG2, "Failed: PVA\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
118 return 0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
119 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
120 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
121
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
122 demuxer_t * demux_open_pva (demuxer_t * demuxer)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
123 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
124 sh_video_t *sh_video = new_sh_video(demuxer,0);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
125 sh_audio_t * sh_audio = new_sh_audio(demuxer,0);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
126 pva_priv_t * priv;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
127 unsigned char * buffer;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
128
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
129
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
130
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
131 stream_reset(demuxer->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
132 stream_seek(demuxer->stream,0);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
133
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
134
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
135
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
136 priv=malloc(sizeof(pva_priv_t));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
137
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
138 if(demuxer->stream->type!=STREAMTYPE_FILE) demuxer->seekable=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
139 else demuxer->seekable=1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
140
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
141 demuxer->priv=priv;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
142 memset(demuxer->priv,0,sizeof(pva_priv_t));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
143
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
144 if(!pva_sync(demuxer))
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
145 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
146 mp_msg(MSGT_DEMUX,MSGL_ERR,"Not a PVA file.\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
147 return NULL;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
148 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
149
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
150 //printf("priv->just_synced %s after initial sync!\n",priv->just_synced?"set":"UNSET");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
151
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
152 demuxer->video->sh=sh_video;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
153 demuxer->audio->sh=sh_audio;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
154 mp_msg(MSGT_DEMUXER,MSGL_INFO,"Opened PVA demuxer...\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
155
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
156 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
157 * Audio and Video codecs:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
158 * the PVA spec only allows MPEG2 video and MPEG layer II audio. No need to check the formats then.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
159 * Moreover, there would be no way to do that since the PVA stream format has no fields to describe
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
160 * the used codecs.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
161 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
162
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
163 sh_video->format=0x10000002;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
164 sh_video->ds=demuxer->video;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
165
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
166 sh_audio->format=0x50;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
167 sh_audio->ds=demuxer->audio;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
168
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
169 priv->last_video_pts=-1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
170 priv->last_audio_pts=-1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
171
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
172 return demuxer;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
173 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
174
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
175 // 0 = EOF or no stream found
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
176 // 1 = successfully read a packet
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
177 int demux_pva_fill_buffer (demuxer_t * demux)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
178 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
179 uint8_t done=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
180 demux_packet_t * dp;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
181 pva_priv_t * priv=demux->priv;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
182 pva_payload_t current_payload;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
183
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
184 while(!done)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
185 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
186 if(!pva_get_payload(demux,&current_payload)) return 0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
187 switch(current_payload.type)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
188 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
189 case VIDEOSTREAM:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
190 if(!current_payload.is_packet_start && priv->last_video_pts==-1)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
191 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
192 /* We should only be here at the beginning of a stream, when we have
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
193 * not yet encountered a valid Video PTS, or after a seek.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
194 * So, skip these starting packets in order not to deliver the
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
195 * player a bogus PTS.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
196 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
197 done=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
198 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
199 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
200 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
201 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
202 * In every other condition, we are delivering the payload. Set this
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
203 * so that the following code knows whether to skip it or read it.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
204 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
205 done=1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
206 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
207 if(current_payload.is_packet_start)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
208 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
209 priv->last_video_pts=((float)current_payload.pts)/90000;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
210 //mp_msg(MSGT_DEMUXER,MSGL_DBG2,"demux_pva: Video PTS=%llu , delivered %f\n",current_payload.pts,priv->last_video_pts);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
211 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
212 if(done)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
213 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
214 dp=new_demux_packet(current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
215 dp->pts=priv->last_video_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
216 stream_read(demux->stream,dp->buffer,current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
217 ds_add_packet(demux->video,dp);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
218 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
219 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
220 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
221 //printf("Skipping %u video bytes\n",current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
222 stream_skip(demux->stream,current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
223 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
224 break;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
225 case MAINAUDIOSTREAM:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
226 if(!current_payload.is_packet_start && priv->last_audio_pts==-1)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
227 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
228 /* Same as above for invalid video PTS, just for audio. */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
229 done=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
230 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
231 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
232 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
233 done=1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
234 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
235 if(current_payload.is_packet_start)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
236 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
237 priv->last_audio_pts=(float)current_payload.pts/90000;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
238 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
239 if(done)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
240 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
241 dp=new_demux_packet(current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
242 dp->pts=priv->last_audio_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
243 stream_read(demux->stream,dp->buffer,current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
244 ds_add_packet(demux->audio,dp);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
245 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
246 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
247 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
248 stream_skip(demux->stream,current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
249 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
250 break;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
251 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
252 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
253 return 1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
254 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
255
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
256 int pva_get_payload(demuxer_t * d,pva_payload_t * payload)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
257 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
258 uint8_t flags,pes_head_len;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
259 uint16_t pack_size;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
260 long long next_offset,pva_payload_start;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
261 unsigned char buffer[256];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
262 demux_packet_t * dp; //hack to deliver the preBytes (see PVA doc)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
263 pva_priv_t * priv=(pva_priv_t *) d->priv;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
264
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
265
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
266 if(d==NULL)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
267 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
268 printf("demux_pva: pva_get_payload got passed a NULL pointer!\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
269 return 0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
270 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
271
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
272
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
273 if(d->stream->eof)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
274 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
275 mp_msg(MSGT_DEMUX,MSGL_V,"demux_pva: pva_get_payload() detected stream->eof!!!\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
276 return 0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
277 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
278
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
279 //printf("priv->just_synced %s\n",priv->just_synced?"SET":"UNSET");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
280 if(!priv->just_synced)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
281 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
282 if(stream_read_word(d->stream) != (('A'<<8)|'V'))
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
283 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
284 mp_msg(MSGT_DEMUX,MSGL_V,"demux_pva: pva_get_payload() missed a SyncWord at %ld!! Trying to sync...\n",stream_tell(d->stream));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
285 if(!pva_sync(d)) return 0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
286 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
287 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
288 if(priv->just_synced)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
289 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
290 payload->type=priv->synced_stream_id;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
291 priv->just_synced=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
292 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
293 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
294 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
295 payload->type=stream_read_char(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
296 stream_skip(d->stream,2); //counter and reserved
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
297 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
298 flags=stream_read_char(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
299 payload->is_packet_start=flags & 0x10;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
300 pack_size=le2me_16(stream_read_word(d->stream));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
301 mp_msg(MSGT_DEMUX,MSGL_DBG2,"demux_pva::pva_get_payload(): pack_size=%u field read at offset %lu\n",pack_size,stream_tell(d->stream)-2);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
302 pva_payload_start=stream_tell(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
303 next_offset=pva_payload_start+pack_size;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
304 if(!payload->is_packet_start)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
305 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
306 payload->offset=stream_tell(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
307 payload->size=pack_size;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
308 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
309 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
310 { //here comes the good part...
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
311 switch(payload->type)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
312 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
313 case VIDEOSTREAM:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
314 payload->pts=le2me_32(stream_read_dword(d->stream));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
315 //printf("Video PTS: %llu\n",payload->pts);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
316 if((flags&0x03) && ((pva_priv_t *)d->priv)->last_video_pts!=-1)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
317 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
318 dp=new_demux_packet(flags&0x03);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
319 stream_read(d->stream,dp->buffer,flags & 0x03); //read PreBytes
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
320 dp->pts=((pva_priv_t *)d->priv)->last_video_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
321 ds_add_packet(d->video,dp);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
322 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
323 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
324 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
325 stream_skip(d->stream,flags&0x03);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
326 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
327
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
328 //now we are at real beginning of payload.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
329 payload->offset=stream_tell(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
330 //size is pack_size minus PTS size minus padding size.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
331 payload->size=pack_size - 4 - (flags & 0x03);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
332 break;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
333 case MAINAUDIOSTREAM:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
334 stream_skip(d->stream,8); //FIXME properly parse PES header.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
335 //assuming byte 8 is PES residual header length.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
336 pes_head_len=stream_read_char(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
337 stream_read(d->stream,buffer,pes_head_len);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
338 //we should now be on start of real payload.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
339 //let's now parse the PTS...
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
340 if((buffer[0] & 0xf0)!=0x20)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
341 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
342 mp_msg(MSGT_DEMUX,MSGL_ERR,"demux_pva: expected audio PTS but badly formatted... (read 0x%02X)\n",buffer[0]);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
343 return;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
344 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
345 payload->pts=0LL;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
346 payload->pts|=((uint64_t)(buffer[0] & 0x0e) << 29);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
347 payload->pts|=buffer[1]<<22;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
348 payload->pts|=(buffer[2] & 0xfe) << 14;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
349 payload->pts|=buffer[3]<<7;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
350 payload->pts|=(buffer[4] & 0xfe) >> 1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
351 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
352 * PTS parsing is hopefully finished.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
353 * Let's now fill in offset and size.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
354 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
355 payload->pts=le2me_64(payload->pts);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
356 payload->offset=stream_tell(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
357 payload->size=pack_size-stream_tell(d->stream)+pva_payload_start;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
358 break;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
359 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
360 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
361 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
362
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
363 int demux_seek_pva(demuxer_t * demuxer,float rel_seek_secs,int flags)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
364 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
365 int total_bitrate=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
366 long dest_offset;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
367 pva_priv_t * priv=demuxer->priv;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
368
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
369 total_bitrate=((sh_audio_t *)demuxer->audio->sh)->i_bps + ((sh_video_t *)demuxer->video->sh)->i_bps;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
370
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
371 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
372 * Compute absolute offset inside the stream. Approximate total bitrate with sum of bitrates
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
373 * reported by the audio and video codecs. The seek is not accurate because, just like
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
374 * with MPEG streams, the bitrate is not constant. Moreover, we do not take into account
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
375 * the overhead caused by PVA and PES headers.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
376 * If the calculated absolute offset is negative, seek to the beginning of the file.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
377 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
378
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
379 dest_offset=stream_tell(demuxer->stream)+rel_seek_secs*total_bitrate;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
380 if(dest_offset<0) dest_offset=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
381
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
382 stream_seek(demuxer->stream,dest_offset);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
383
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
384 if(!pva_sync(demuxer))
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
385 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
386 mp_msg(MSGT_DEMUX,MSGL_V,"demux_pva: Couldn't seek!\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
387 return 0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
388 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
389
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
390 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
391 * Reset the PTS info inside the pva_priv_t structure. This way we don't deliver
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
392 * data with the wrong PTSs (the ones we had before seeking).
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
393 *
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
394 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
395
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
396 priv->last_video_pts=-1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
397 priv->last_audio_pts=-1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
398
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
399 return 1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
400 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
401
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
402
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
403
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
404 void demux_close_pva(demuxer_t * demuxer)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
405 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
406 if(demuxer->priv)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
407 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
408 free(demuxer->priv);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
409 demuxer->priv=NULL;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
410 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
411 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
412