annotate libmpdemux/muxer_rawvideo.c @ 12584:d3607c8774c6

10l for a copy and paste error noticed by Alex.
author diego
date Mon, 14 Jun 2004 09:57:02 +0000
parents b962aaad2940
children ca4c07c87e6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
1
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
2 #include <stdio.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
3 #include <stdlib.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
4 #include <string.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
5 #include <inttypes.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
6 #include <unistd.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
7
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
8 #include "config.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
9 #include "../version.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
10
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
11 //#include "stream.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
12 //#include "demuxer.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
13 //#include "stheader.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
14
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
15 #include "wine/mmreg.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
16 #include "wine/avifmt.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
17 #include "wine/vfw.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
18 #include "bswap.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
19
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
20 #include "muxer.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
21
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
22 static muxer_stream_t* rawvideofile_new_stream(muxer_t *muxer,int type){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
23 muxer_stream_t* s;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
24 if (!muxer) return NULL;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
25 if (type == MUXER_TYPE_AUDIO) {
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
26 printf("Rawvideo muxer does not support audio !\n");
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
27 return NULL;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
28 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
29 if(muxer->avih.dwStreams>=1){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
30 printf("Too many streams! Rawvideo muxer supports only one video stream !\n");
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
31 return NULL;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
32 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
33 s=malloc(sizeof(muxer_stream_t));
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
34 memset(s,0,sizeof(muxer_stream_t));
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
35 if(!s) return NULL; // no mem!?
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
36 muxer->streams[muxer->avih.dwStreams]=s;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
37 s->type=type;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
38 s->id=muxer->avih.dwStreams;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
39 s->timer=0.0;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
40 s->size=0;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
41 s->muxer=muxer;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
42 switch(type){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
43 case MUXER_TYPE_VIDEO:
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
44 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
45 s->h.fccType=streamtypeVIDEO;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
46 if(!muxer->def_v) muxer->def_v=s;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
47 break;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
48 default:
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
49 printf("WarninG! unknown stream type: %d\n",type);
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
50 return NULL;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
51 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
52 muxer->avih.dwStreams++;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
53 return s;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
54 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
55
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
56 static void write_rawvideo_chunk(FILE *f,int len,void* data){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
57 if(len>0){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
58 if(data){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
59 // DATA
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
60 fwrite(data,len,1,f);
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
61 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
62 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
63 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
64
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
65 static void rawvideofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
66 muxer_t *muxer=s->muxer;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
67
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
68 // write out the chunk:
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
69 write_rawvideo_chunk(muxer->file,len,s->buffer); /* unsigned char */
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
70
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
71 // alter counters:
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
72 if(s->h.dwSampleSize){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
73 // CBR
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
74 s->h.dwLength+=len/s->h.dwSampleSize;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
75 if(len%s->h.dwSampleSize) printf("Warning! len isn't divisable by samplesize!\n");
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
76 } else {
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
77 // VBR
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
78 s->h.dwLength++;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
79 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
80 s->timer=(double)s->h.dwLength*s->h.dwScale/s->h.dwRate;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
81 s->size+=len;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
82 // if((unsigned int)len>s->h.dwSuggestedBufferSize) s->h.dwSuggestedBufferSize=len;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
83
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
84 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
85
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
86 static void rawvideofile_write_header(muxer_t *muxer){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
87 return;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
88 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
89
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
90 static void rawvideofile_write_index(muxer_t *muxer){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
91 return;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
92 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
93
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
94 void muxer_init_muxer_rawvideo(muxer_t *muxer){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
95 muxer->cont_new_stream = &rawvideofile_new_stream;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
96 muxer->cont_write_chunk = &rawvideofile_write_chunk;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
97 muxer->cont_write_header = &rawvideofile_write_header;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
98 muxer->cont_write_index = &rawvideofile_write_index;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
99 }