annotate libmpdemux/demux_mpc.c @ 16005:9f297ab810a0

Moved some entries from playback problems to video/audio driver section where they belong.
author diego
date Tue, 19 Jul 2005 00:45:18 +0000
parents 087142ef3a2d
children f482bbb5fad9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15958
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
1
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
2 #include "config.h"
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
3
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
4 #include <stdlib.h>
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
5 #include <stdio.h>
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
6 #include <string.h>
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
7 #include "mp_msg.h"
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
8 #include "bswap.h"
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
9 #include "stream.h"
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
10 #include "demuxer.h"
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
11 #include "stheader.h"
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
12
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
13
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
14 #define HDR_SIZE (6 * 4)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
15
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
16 typedef struct da_priv {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
17 float last_pts;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
18 uint32_t dword;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
19 int pos;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
20 } da_priv_t;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
21
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
22 extern void free_sh_audio(sh_audio_t* sh);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
23
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
24 static uint32_t get_bits(da_priv_t* priv, stream_t* s, int bits) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
25 uint32_t out = priv->dword;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
26 uint32_t mask = (1 << bits) - 1;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
27 priv->pos += bits;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
28 if (priv->pos < 32) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
29 out >>= (32 - priv->pos);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
30 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
31 else {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
32 stream_read(s, (void *)&priv->dword, 4);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
33 le2me_32(priv->dword);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
34 priv->pos -= 32;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
35 if (priv->pos) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
36 out <<= priv->pos;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
37 out |= priv->dword >> (32 - priv->pos);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
38 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
39 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
40 return out & mask;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
41 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
42
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
43 int demux_mpc_open(demuxer_t* demuxer) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
44 stream_t *s = demuxer->stream;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
45 sh_audio_t* sh_audio;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
46 uint8_t hdr[HDR_SIZE];
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
47 da_priv_t* priv;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
48 int i;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
49
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
50 if (stream_read(s, hdr, HDR_SIZE) != HDR_SIZE)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
51 return 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
52 for (i = 0; i < 30000 && !s->eof; i++) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
53 if (hdr[0] == 'M' && hdr[1] == 'P' && hdr[2] == '+')
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
54 break;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
55 memmove(hdr, &hdr[1], HDR_SIZE - 1);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
56 stream_read(s, &hdr[HDR_SIZE - 1], 1);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
57 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
58
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
59 if (hdr[0] != 'M' || hdr[1] != 'P' || hdr[2] != '+')
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
60 return 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
61
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
62 sh_audio = new_sh_audio(demuxer,0);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
63
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
64 {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
65 char *wf = (char *)calloc(1, sizeof(WAVEFORMATEX) + HDR_SIZE);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
66 char *header = &wf[sizeof(WAVEFORMATEX)];
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
67 const int freqs[4] = {44100, 48000, 37800, 32000};
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
68 sh_audio->format = mmioFOURCC('M', 'P', 'C', ' ');
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
69 memcpy(header, hdr, HDR_SIZE);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
70 sh_audio->wf = (WAVEFORMATEX *)wf;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
71 sh_audio->wf->wFormatTag = sh_audio->format;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
72 sh_audio->wf->nChannels = 2;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
73 sh_audio->wf->nSamplesPerSec = freqs[header[10] & 3];
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
74 sh_audio->wf->nBlockAlign = 32 * 36;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
75 sh_audio->wf->wBitsPerSample = 16;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
76 sh_audio->wf->nAvgBytesPerSec = 128 * 1024; // dummy to make mencoder not hang
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
77 sh_audio->wf->cbSize = HDR_SIZE;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
78 demuxer->movi_start = stream_tell(s);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
79 demuxer->movi_end = s->end_pos;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
80 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
81
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
82 priv = (da_priv_t *)malloc(sizeof(da_priv_t));
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
83 priv->last_pts = -1;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
84 priv->dword = 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
85 priv->pos = 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
86 stream_read(s, (void *)&priv->dword, 4);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
87 priv->pos = 8;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
88 demuxer->priv = priv;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
89 demuxer->audio->id = 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
90 demuxer->audio->sh = sh_audio;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
91 sh_audio->ds = demuxer->audio;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
92 sh_audio->samplerate = sh_audio->wf->nSamplesPerSec;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
93 sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
94 sh_audio->audio.dwSampleSize = 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
95 sh_audio->audio.dwScale = 32 * 36;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
96 sh_audio->audio.dwRate = sh_audio->samplerate;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
97
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
98 return 1;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
99 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
100
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
101 int demux_mpc_fill_buffer(demux_stream_t *ds) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
102 int l;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
103 int bit_len;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
104 demux_packet_t* dp;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
105 sh_audio_t* sh_audio = ds->sh;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
106 demuxer_t* demux = ds->demuxer;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
107 da_priv_t* priv = demux->priv;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
108 stream_t* s = demux->stream;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
109 sh_audio = ds->sh;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
110
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
111 if (s->eof)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
112 return 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
113
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
114 bit_len = get_bits(priv, s, 20);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
115 dp = new_demux_packet((bit_len + 7) / 8);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
116 for (l = 0; l < (bit_len / 8); l++)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
117 dp->buffer[l] = get_bits(priv, s, 8);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
118 bit_len %= 8;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
119 if (bit_len)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
120 dp->buffer[l] = get_bits(priv, s, bit_len) << (8 - bit_len);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
121 if (priv->last_pts < 0)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
122 priv->last_pts = 0;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
123 else
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
124 priv->last_pts += (36 * 32) / (float)sh_audio->samplerate;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
125 ds->pts = priv->last_pts - (ds_tell_pts(demux->audio) -
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
126 sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
127 ds_add_packet(ds, dp);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
128 return 1;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
129 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
130
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
131 void demux_mpc_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
132 // TODO
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
133 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
134
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
135 void demux_close_mpc(demuxer_t* demuxer) {
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
136 da_priv_t* priv = demuxer->priv;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
137
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
138 if(!priv)
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
139 return;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
140 free(priv);
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
141 }
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
142
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
143 int demux_mpc_control(demuxer_t *demuxer,int cmd, void *arg){
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
144 return DEMUXER_CTRL_NOTIMPL;
087142ef3a2d musepack demuxing and decoding support (demuxing is v7 bitstream only).
reimar
parents:
diff changeset
145 }