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