comparison libmpdemux/muxer_rawaudio.c @ 15754:7b0599d9614a

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