annotate libmpdemux/muxer_rawvideo.c @ 35885:3389262720da

Fix previous commit, off_t must be replaced by int64_t The commit replacing off_t by uint64_t was by accident, I meant to commit this variant. off_t must be replaced by a signed type to avoid breaking things like seeking backwards and also detecting errors from e.g. lseek without too complex hacks.
author reimar
date Sat, 16 Mar 2013 13:38:34 +0000
parents d643e4643313
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
1 /*
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
2 * This file is part of MPlayer.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
3 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
5 * it under the terms of the GNU General Public License as published by
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
7 * (at your option) any later version.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
8 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
12 * GNU General Public License for more details.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
13 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
14 * You should have received a copy of the GNU General Public License along
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26570
diff changeset
17 */
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
18
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
19 #include <stdio.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
20 #include <stdlib.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
21 #include <string.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
22 #include <inttypes.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
23 #include <unistd.h>
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
24
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
25 #include "config.h"
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 21660
diff changeset
26 //#include "stream/stream.h"
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
27 //#include "demuxer.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
28 //#include "stheader.h"
13183
ca4c07c87e6f use correct headers
rathann
parents: 12016
diff changeset
29 #include "aviheader.h"
ca4c07c87e6f use correct headers
rathann
parents: 12016
diff changeset
30 #include "ms_hdr.h"
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
31
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 21660
diff changeset
32 #include "stream/stream.h"
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
33 #include "muxer.h"
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
34
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
35 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
36 muxer_stream_t* s;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
37 if (!muxer) return NULL;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
38 s=malloc(sizeof(muxer_stream_t));
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
39 memset(s,0,sizeof(muxer_stream_t));
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
40 if(!s) return NULL; // no mem!?
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
41 muxer->streams[muxer->avih.dwStreams]=s;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
42 s->type=type;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
43 s->id=muxer->avih.dwStreams;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
44 s->timer=0.0;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
45 s->size=0;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
46 s->muxer=muxer;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
47 switch(type){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
48 case MUXER_TYPE_VIDEO:
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
49 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
50 s->h.fccType=streamtypeVIDEO;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
51 if(!muxer->def_v) muxer->def_v=s;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
52 break;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
53 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
54 muxer->avih.dwStreams++;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
55 return s;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
56 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
57
21660
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21421
diff changeset
58 static void write_rawvideo_chunk(stream_t *stream,int len,void* data){
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
59 if(len>0){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
60 if(data){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
61 // DATA
21660
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21421
diff changeset
62 stream_write_buffer(stream,data,len);
12016
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 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
66
17487
fa17424b4c7b change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents: 17023
diff changeset
67 static void rawvideofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
68 muxer_t *muxer=s->muxer;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
69
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
70 // write out the chunk:
16805
50fb26acbcba processing audio is sometimes essential for a/v sync, so 1000l to
rfelker
parents: 14753
diff changeset
71 if (s->type == MUXER_TYPE_VIDEO)
21660
ca9da45d13e9 muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents: 21421
diff changeset
72 write_rawvideo_chunk(muxer->stream,len,s->buffer); /* unsigned char */
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
73
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
74 // 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
75
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
76 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
77
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
78 static void rawvideofile_write_header(muxer_t *muxer){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
79 return;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
80 }
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
81
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
82 static void rawvideofile_write_index(muxer_t *muxer){
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
83 return;
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
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 13183
diff changeset
86 int muxer_init_muxer_rawvideo(muxer_t *muxer){
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
87 muxer->cont_new_stream = &rawvideofile_new_stream;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
88 muxer->cont_write_chunk = &rawvideofile_write_chunk;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
89 muxer->cont_write_header = &rawvideofile_write_header;
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
90 muxer->cont_write_index = &rawvideofile_write_index;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 13183
diff changeset
91 return 1;
12016
b962aaad2940 rawvideo muxer patch by John Earl <jwe21@cam.ac.uk>
ranma
parents:
diff changeset
92 }