annotate libmpdemux/demux_pva.c @ 7491:87197e110b4f

accepted. so we're now 110% gpl...
author arpi
date Mon, 23 Sep 2002 19:02:21 +0000
parents c4434bdf6e51
children eb3afb162aa4
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
7472
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 7364
diff changeset
21 #include <stdio.h>
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 7364
diff changeset
22 #include <stdlib.h>
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 7364
diff changeset
23 #include <string.h>
7364
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
24
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
25 #include "config.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
26 #include "mp_msg.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
27 #include "help_mp.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
28
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
29 #include "stream.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
30 #include "demuxer.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
31 #include "stheader.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 #include "bswap.h"
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
34
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 * #defines below taken from PVA spec (see URL above)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
37 */
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 PVA_MAX_VIDEO_PACK_LEN 6*1024
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
40
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
41 #define VIDEOSTREAM 0x01
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
42 #define MAINAUDIOSTREAM 0x02
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
43
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
44 typedef struct {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
45 unsigned long offset;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
46 long size;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
47 uint8_t type;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
48 uint8_t is_packet_start;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
49 uint64_t pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
50 } pva_payload_t;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
51
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
52
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
53 typedef struct {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
54 float last_audio_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
55 float last_video_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
56 uint8_t just_synced;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
57 uint8_t synced_stream_id;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
58 } pva_priv_t;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
59
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 int pva_sync(demuxer_t * demuxer)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
62 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
63 uint8_t buffer[5]={0,0,0,0,0};
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
64 int count;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
65 pva_priv_t * priv = (pva_priv_t *) demuxer->priv;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
66
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
67 /* 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
68 * 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
69 * already been allocated, otherwise we will dereference NULL and segfault.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
70 * 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
71 * 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
72 * 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
73 * from pipes and such.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
74 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
75
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
76 uint8_t local_synced=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
77 uint8_t * syncedptr;
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 syncedptr=(priv==NULL)?&local_synced:&priv->just_synced;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
80
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 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
83 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
84 buffer[0]=buffer[1];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
85 buffer[1]=buffer[2];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
86 buffer[2]=buffer[3];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
87 buffer[3]=buffer[4];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
88 buffer[4]=stream_read_char(demuxer->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
89 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
90 * 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
91 * 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
92 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
93 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
94 //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
95 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
96 if(*syncedptr)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
97 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
98 if(priv!=NULL) priv->synced_stream_id=buffer[2];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
99 return 1;
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 else
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 return 0;
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 }
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 int pva_check_file(demuxer_t * demuxer)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
108 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
109 uint8_t buffer[5]={0,0,0,0,0};
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
110 mp_msg(MSGT_DEMUX, MSGL_V, "Checking for PVA\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
111 stream_read(demuxer->stream,buffer,5);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
112 if(buffer[0]=='A' && buffer[1] == 'V' && buffer[4] == 0x55)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
113 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
114 mp_msg(MSGT_DEMUX,MSGL_DBG2, "Success: PVA\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
115 return 1;
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 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
118 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
119 mp_msg(MSGT_DEMUX,MSGL_DBG2, "Failed: PVA\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
120 return 0;
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 }
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 demuxer_t * demux_open_pva (demuxer_t * demuxer)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
125 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
126 sh_video_t *sh_video = new_sh_video(demuxer,0);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
127 sh_audio_t * sh_audio = new_sh_audio(demuxer,0);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
128 pva_priv_t * priv;
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 stream_reset(demuxer->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
131 stream_seek(demuxer->stream,0);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
132
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 priv=malloc(sizeof(pva_priv_t));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
136
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
137 if(demuxer->stream->type!=STREAMTYPE_FILE) demuxer->seekable=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
138 else demuxer->seekable=1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
139
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
140 demuxer->priv=priv;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
141 memset(demuxer->priv,0,sizeof(pva_priv_t));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
142
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
143 if(!pva_sync(demuxer))
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
144 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
145 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
146 return NULL;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
147 }
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 //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
150
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
151 demuxer->video->sh=sh_video;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
152 demuxer->audio->sh=sh_audio;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
153 mp_msg(MSGT_DEMUXER,MSGL_INFO,"Opened PVA demuxer...\n");
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
154
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 * Audio and Video codecs:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
157 * 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
158 * 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
159 * the used codecs.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
160 */
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 sh_video->format=0x10000002;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
163 sh_video->ds=demuxer->video;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
164
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
165 sh_audio->format=0x50;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
166 sh_audio->ds=demuxer->audio;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
167
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
168 priv->last_video_pts=-1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
169 priv->last_audio_pts=-1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
170
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
171 return demuxer;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
172 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
173
7472
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 7364
diff changeset
174 int pva_get_payload(demuxer_t * d,pva_payload_t * payload);
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 7364
diff changeset
175
7364
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
176 // 0 = EOF or no stream found
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
177 // 1 = successfully read a packet
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
178 int demux_pva_fill_buffer (demuxer_t * demux)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
179 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
180 uint8_t done=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
181 demux_packet_t * dp;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
182 pva_priv_t * priv=demux->priv;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
183 pva_payload_t current_payload;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
184
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
185 while(!done)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
186 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
187 if(!pva_get_payload(demux,&current_payload)) return 0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
188 switch(current_payload.type)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
189 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
190 case VIDEOSTREAM:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
191 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
192 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
193 /* 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
194 * 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
195 * 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
196 * player a bogus PTS.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
197 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
198 done=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
199 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
200 else
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 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
203 * 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
204 * 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
205 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
206 done=1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
207 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
208 if(current_payload.is_packet_start)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
209 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
210 priv->last_video_pts=((float)current_payload.pts)/90000;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
211 //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
212 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
213 if(done)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
214 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
215 dp=new_demux_packet(current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
216 dp->pts=priv->last_video_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
217 stream_read(demux->stream,dp->buffer,current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
218 ds_add_packet(demux->video,dp);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
219 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
220 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
221 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
222 //printf("Skipping %u video bytes\n",current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
223 stream_skip(demux->stream,current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
224 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
225 break;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
226 case MAINAUDIOSTREAM:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
227 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
228 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
229 /* Same as above for invalid video PTS, just for audio. */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
230 done=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
231 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
232 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
233 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
234 done=1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
235 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
236 if(current_payload.is_packet_start)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
237 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
238 priv->last_audio_pts=(float)current_payload.pts/90000;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
239 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
240 if(done)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
241 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
242 dp=new_demux_packet(current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
243 dp->pts=priv->last_audio_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
244 stream_read(demux->stream,dp->buffer,current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
245 ds_add_packet(demux->audio,dp);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
246 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
247 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
248 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
249 stream_skip(demux->stream,current_payload.size);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
250 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
251 break;
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 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
254 return 1;
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
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
257 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
258 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
259 uint8_t flags,pes_head_len;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
260 uint16_t pack_size;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
261 long long next_offset,pva_payload_start;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
262 unsigned char buffer[256];
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
263 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
264 pva_priv_t * priv=(pva_priv_t *) d->priv;
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
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
267 if(d==NULL)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
268 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
269 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
270 return 0;
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
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
274 if(d->stream->eof)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
275 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
276 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
277 return 0;
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
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
280 //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
281 if(!priv->just_synced)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
282 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
283 if(stream_read_word(d->stream) != (('A'<<8)|'V'))
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
284 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
285 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
286 if(!pva_sync(d)) return 0;
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 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
289 if(priv->just_synced)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
290 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
291 payload->type=priv->synced_stream_id;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
292 priv->just_synced=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
293 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
294 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
295 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
296 payload->type=stream_read_char(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
297 stream_skip(d->stream,2); //counter and reserved
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
298 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
299 flags=stream_read_char(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
300 payload->is_packet_start=flags & 0x10;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
301 pack_size=le2me_16(stream_read_word(d->stream));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
302 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
303 pva_payload_start=stream_tell(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
304 next_offset=pva_payload_start+pack_size;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
305 if(!payload->is_packet_start)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
306 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
307 payload->offset=stream_tell(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
308 payload->size=pack_size;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
309 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
310 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
311 { //here comes the good part...
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
312 switch(payload->type)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
313 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
314 case VIDEOSTREAM:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
315 payload->pts=le2me_32(stream_read_dword(d->stream));
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
316 //printf("Video PTS: %llu\n",payload->pts);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
317 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
318 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
319 dp=new_demux_packet(flags&0x03);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
320 stream_read(d->stream,dp->buffer,flags & 0x03); //read PreBytes
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
321 dp->pts=((pva_priv_t *)d->priv)->last_video_pts;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
322 ds_add_packet(d->video,dp);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
323 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
324 else
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
325 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
326 stream_skip(d->stream,flags&0x03);
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
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
329 //now we are at real beginning of payload.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
330 payload->offset=stream_tell(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
331 //size is pack_size minus PTS size minus padding size.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
332 payload->size=pack_size - 4 - (flags & 0x03);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
333 break;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
334 case MAINAUDIOSTREAM:
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
335 stream_skip(d->stream,8); //FIXME properly parse PES header.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
336 //assuming byte 8 is PES residual header length.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
337 pes_head_len=stream_read_char(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
338 stream_read(d->stream,buffer,pes_head_len);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
339 //we should now be on start of real payload.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
340 //let's now parse the PTS...
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
341 if((buffer[0] & 0xf0)!=0x20)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
342 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
343 mp_msg(MSGT_DEMUX,MSGL_ERR,"demux_pva: expected audio PTS but badly formatted... (read 0x%02X)\n",buffer[0]);
7472
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 7364
diff changeset
344 return 0;
7364
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
345 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
346 payload->pts=0LL;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
347 payload->pts|=((uint64_t)(buffer[0] & 0x0e) << 29);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
348 payload->pts|=buffer[1]<<22;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
349 payload->pts|=(buffer[2] & 0xfe) << 14;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
350 payload->pts|=buffer[3]<<7;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
351 payload->pts|=(buffer[4] & 0xfe) >> 1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
352 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
353 * PTS parsing is hopefully finished.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
354 * Let's now fill in offset and size.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
355 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
356 payload->pts=le2me_64(payload->pts);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
357 payload->offset=stream_tell(d->stream);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
358 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
359 break;
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 }
7472
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 7364
diff changeset
362 return 1;
7364
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
363 }
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 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
366 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
367 int total_bitrate=0;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
368 long dest_offset;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
369 pva_priv_t * priv=demuxer->priv;
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 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
372
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
373 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
374 * 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
375 * 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
376 * 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
377 * the overhead caused by PVA and PES headers.
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
378 * 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
379 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
380
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
381 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
382 if(dest_offset<0) dest_offset=0;
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 stream_seek(demuxer->stream,dest_offset);
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 if(!pva_sync(demuxer))
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
387 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
388 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
389 return 0;
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
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
392 /*
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
393 * 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
394 * 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
395 *
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
396 */
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
397
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
398 priv->last_video_pts=-1;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
399 priv->last_audio_pts=-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 return 1;
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
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 void demux_close_pva(demuxer_t * demuxer)
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 if(demuxer->priv)
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
409 {
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
410 free(demuxer->priv);
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
411 demuxer->priv=NULL;
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
412 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
413 }
b2445802532c .PVA (mpeg-like fileformat used by MultiDec && WinTV) demuxer
arpi
parents:
diff changeset
414