annotate libmpdemux/muxer_rawaudio.c @ 16807:f11cf6fe9599

Formal syncing. Typo hunting.
author jheryan
date Wed, 19 Oct 2005 12:09:56 +0000
parents ed3fec6506c4
children dd5be8f8d16d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15754
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
1 #include <stdio.h>
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
2 #include <stdlib.h>
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
3 #include <string.h>
15774
ed3fec6506c4 Fix off_t on OSX, thanks to Steven M. Schultz
ranma
parents: 15754
diff changeset
4 #include <sys/types.h>
15754
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
5
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
6 #include "help_mp.h"
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
7 #include "mp_msg.h"
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
8
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
9 #include "aviheader.h"
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
10 #include "ms_hdr.h"
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
11
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
12 #include "muxer.h"
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
13
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
14 static muxer_stream_t* rawaudiofile_new_stream(muxer_t *muxer,int type){
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
15 muxer_stream_t* s;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
16 if (!muxer) return NULL;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
17 if(type==MUXER_TYPE_AUDIO && muxer->avih.dwStreams>=1){
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
18 mp_msg(MSGT_MUXER,MSGL_ERR,MSGTR_TooManyStreams" "MSGTR_RawMuxerOnlyOneStream);
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
19 return NULL;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
20 }
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
21 s=malloc(sizeof(muxer_stream_t));
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
22 memset(s,0,sizeof(muxer_stream_t));
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
23 if(!s) return NULL; // no mem!?
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
24 muxer->streams[muxer->avih.dwStreams]=s;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
25 s->type=type;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
26 s->id=muxer->avih.dwStreams;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
27 s->timer=0.0;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
28 s->size=0;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
29 s->muxer=muxer;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
30 switch(type){
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
31 case MUXER_TYPE_AUDIO:
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
32 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
33 s->h.fccType=streamtypeAUDIO;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
34 muxer->avih.dwStreams++;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
35 break;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
36 case MUXER_TYPE_VIDEO:
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
37 mp_msg(MSGT_MUXER,MSGL_WARN,MSGTR_IgnoringVideoStream);
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
38 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
39 s->h.fccType=streamtypeAUDIO;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
40 break;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
41 default:
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
42 mp_msg(MSGT_MUXER,MSGL_ERR,MSGTR_UnknownStreamType,type);
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
43 return NULL;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
44 }
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
45 return s;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
46 }
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
47
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
48 static void rawaudiofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
49 muxer_t *muxer=s->muxer;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
50
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
51 // write out the chunk:
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
52 if (s->type==MUXER_TYPE_AUDIO)
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
53 fwrite(s->buffer,len,1,muxer->file);
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
54
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
55 // alter counters:
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
56 if(s->h.dwSampleSize){
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
57 // CBR
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
58 s->h.dwLength+=len/s->h.dwSampleSize;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
59 if(len%s->h.dwSampleSize)
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
60 mp_msg(MSGT_MUXER,MSGL_WARN,MSGTR_WarningLenIsntDivisible);
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
61 } else {
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
62 // VBR
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
63 s->h.dwLength++;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
64 }
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
65 s->timer=(double)s->h.dwLength*s->h.dwScale/s->h.dwRate;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
66 s->size+=len;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
67 }
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
68
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
69 static void rawaudiofile_write_header(muxer_t *muxer){
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
70 return;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
71 }
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
72
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
73 static void rawaudiofile_write_index(muxer_t *muxer){
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
74 return;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
75 }
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
76
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
77 int muxer_init_muxer_rawaudio(muxer_t *muxer){
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
78 muxer->cont_new_stream = &rawaudiofile_new_stream;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
79 muxer->cont_write_chunk = &rawaudiofile_write_chunk;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
80 muxer->cont_write_header = &rawaudiofile_write_header;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
81 muxer->cont_write_index = &rawaudiofile_write_index;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
82 return 1;
7b0599d9614a rawaudio muxer
ranma
parents:
diff changeset
83 }