comparison libmpdemux/muxer_lavf.c @ 26702:b5e7063ffade

cosmetics: wording/spelling fixes
author diego
date Sun, 11 May 2008 12:03:26 +0000
parents 1af41774481b
children e77942d2d664
comparison
equal deleted inserted replaced
26701:85dc7d81935c 26702:b5e7063ffade
62 {"o", &mux_avopt, CONF_TYPE_STRING, 0, 0, 0, NULL}, 62 {"o", &mux_avopt, CONF_TYPE_STRING, 0, 0, 0, NULL},
63 63
64 {NULL, NULL, 0, 0, 0, 0, NULL} 64 {NULL, NULL, 0, 0, 0, 0, NULL}
65 }; 65 };
66 66
67 static muxer_t *priv_data; // This should be transmitted to mp_open() through the filename 67 /* This should be transmitted to mp_open() through the filename when
68 // when thread saftey is needed but mplayer == no threads and 68 * thread safety is needed but MPlayer == no threads and especially
69 // especially not multiple muxers being inited at once so theres 69 * not multiple muxers being initialized at once so there is no
70 // no point in the extra complexity, a static is simpler. 70 * point in the extra complexity, a static is simpler. */
71 static muxer_t *priv_data;
71 72
72 static int mp_open(URLContext *h, const char *filename, int flags) 73 static int mp_open(URLContext *h, const char *filename, int flags)
73 { 74 {
74 h->priv_data= priv_data; 75 h->priv_data= priv_data;
75 return 0; 76 return 0;
134 muxer_stream_priv_t *spriv; 135 muxer_stream_priv_t *spriv;
135 AVCodecContext *ctx; 136 AVCodecContext *ctx;
136 137
137 if(!muxer || (type != MUXER_TYPE_VIDEO && type != MUXER_TYPE_AUDIO)) 138 if(!muxer || (type != MUXER_TYPE_VIDEO && type != MUXER_TYPE_AUDIO))
138 { 139 {
139 mp_msg(MSGT_MUXER, MSGL_ERR, "UNKNOW TYPE %d\n", type); 140 mp_msg(MSGT_MUXER, MSGL_ERR, "UNKNOWN TYPE %d\n", type);
140 return NULL; 141 return NULL;
141 } 142 }
142 143
143 stream = calloc(1, sizeof(muxer_stream_t)); 144 stream = calloc(1, sizeof(muxer_stream_t));
144 if(!stream) 145 if(!stream)
145 { 146 {
146 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not alloc muxer_stream, EXIT\n"); 147 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate muxer_stream, EXIT.\n");
147 return NULL; 148 return NULL;
148 } 149 }
149 muxer->streams[muxer->avih.dwStreams] = stream; 150 muxer->streams[muxer->avih.dwStreams] = stream;
150 stream->b_buffer = malloc(2048); 151 stream->b_buffer = malloc(2048);
151 if(!stream->b_buffer) 152 if(!stream->b_buffer)
152 { 153 {
153 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not alloc b_buffer, EXIT\n"); 154 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate b_buffer, EXIT.\n");
154 free(stream); 155 free(stream);
155 return NULL; 156 return NULL;
156 } 157 }
157 stream->b_buffer_size = 2048; 158 stream->b_buffer_size = 2048;
158 stream->b_buffer_ptr = 0; 159 stream->b_buffer_ptr = 0;
167 stream->priv = spriv; 168 stream->priv = spriv;
168 169
169 spriv->avstream = av_new_stream(priv->oc, 1); 170 spriv->avstream = av_new_stream(priv->oc, 1);
170 if(!spriv->avstream) 171 if(!spriv->avstream)
171 { 172 {
172 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not alloc avstream, EXIT\n"); 173 mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate avstream, EXIT.\n");
173 return NULL; 174 return NULL;
174 } 175 }
175 spriv->avstream->stream_copy = 1; 176 spriv->avstream->stream_copy = 1;
176 177
177 ctx = spriv->avstream->codec; 178 ctx = spriv->avstream->codec;
230 { 231 {
231 ctx->extradata_size = stream->wf->cbSize; 232 ctx->extradata_size = stream->wf->cbSize;
232 memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size); 233 memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size);
233 } 234 }
234 else 235 else
235 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(audio stream) error! couldn't allocate %d bytes for extradata\n", 236 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(audio stream) error! Could not allocate %d bytes for extradata.\n",
236 stream->wf->cbSize); 237 stream->wf->cbSize);
237 } 238 }
238 } 239 }
239 else if(stream->type == MUXER_TYPE_VIDEO) 240 else if(stream->type == MUXER_TYPE_VIDEO)
240 { 241 {
255 ctx->extradata = av_malloc(ctx->extradata_size); 256 ctx->extradata = av_malloc(ctx->extradata_size);
256 if(ctx->extradata != NULL) 257 if(ctx->extradata != NULL)
257 memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size); 258 memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size);
258 else 259 else
259 { 260 {
260 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! couldn't allocate %d bytes for extradata\n", 261 mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! Could not allocate %d bytes for extradata.\n",
261 ctx->extradata_size); 262 ctx->extradata_size);
262 ctx->extradata_size = 0; 263 ctx->extradata_size = 0;
263 } 264 }
264 } 265 }
265 } 266 }
288 pkt.pts = (pts / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5); 289 pkt.pts = (pts / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
289 //fprintf(stderr, "%Ld %Ld id:%d tb:%f %f\n", pkt.dts, pkt.pts, pkt.stream_index, av_q2d(priv->oc->streams[pkt.stream_index]->time_base), stream->timer); 290 //fprintf(stderr, "%Ld %Ld id:%d tb:%f %f\n", pkt.dts, pkt.pts, pkt.stream_index, av_q2d(priv->oc->streams[pkt.stream_index]->time_base), stream->timer);
290 291
291 if(av_interleaved_write_frame(priv->oc, &pkt) != 0) //av_write_frame(priv->oc, &pkt) 292 if(av_interleaved_write_frame(priv->oc, &pkt) != 0) //av_write_frame(priv->oc, &pkt)
292 { 293 {
293 mp_msg(MSGT_MUXER, MSGL_ERR, "Error while writing frame\n"); 294 mp_msg(MSGT_MUXER, MSGL_ERR, "Error while writing frame.\n");
294 } 295 }
295 } 296 }
296 297
297 return; 298 return;
298 } 299 }
347 } 348 }
348 349
349 mp_msg(MSGT_MUXER, MSGL_WARN, "** MUXER_LAVF *****************************************************************\n"); 350 mp_msg(MSGT_MUXER, MSGL_WARN, "** MUXER_LAVF *****************************************************************\n");
350 mp_msg(MSGT_MUXER, MSGL_WARN, 351 mp_msg(MSGT_MUXER, MSGL_WARN,
351 "REMEMBER: MEncoder's libavformat muxing is presently broken and can generate\n" 352 "REMEMBER: MEncoder's libavformat muxing is presently broken and can generate\n"
352 "INCORRECT files in the presence of B frames. Moreover, due to bugs MPlayer\n" 353 "INCORRECT files in the presence of B-frames. Moreover, due to bugs MPlayer\n"
353 "will play these INCORRECT files as if nothing were wrong!\n" 354 "will play these INCORRECT files as if nothing were wrong!\n"
354 "*******************************************************************************\n"); 355 "*******************************************************************************\n");
355 356
356 priv = (muxer_priv_t *) calloc(1, sizeof(muxer_priv_t)); 357 priv = (muxer_priv_t *) calloc(1, sizeof(muxer_priv_t));
357 if(priv == NULL) 358 if(priv == NULL)
358 return 0; 359 return 0;
359 360
360 priv->oc = av_alloc_format_context(); 361 priv->oc = av_alloc_format_context();
361 if(!priv->oc) 362 if(!priv->oc)
362 { 363 {
363 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't get format context\n"); 364 mp_msg(MSGT_MUXER, MSGL_FATAL, "Could not get format context.\n");
364 goto fail; 365 goto fail;
365 } 366 }
366 367
367 if(conf_format) 368 if(conf_format)
368 fmt = guess_format(conf_format, NULL, NULL); 369 fmt = guess_format(conf_format, NULL, NULL);
369 if(! fmt) 370 if(! fmt)
370 fmt = guess_format(NULL, out_filename, NULL); 371 fmt = guess_format(NULL, out_filename, NULL);
371 if(! fmt) 372 if(! fmt)
372 { 373 {
373 mp_msg(MSGT_MUXER, MSGL_FATAL, "CAN'T GET SPECIFIED FORMAT\n"); 374 mp_msg(MSGT_MUXER, MSGL_FATAL, "Cannot get specified format.\n");
374 goto fail; 375 goto fail;
375 } 376 }
376 priv->oc->oformat = fmt; 377 priv->oc->oformat = fmt;
377 378
378 379
379 if(av_set_parameters(priv->oc, NULL) < 0) 380 if(av_set_parameters(priv->oc, NULL) < 0)
380 { 381 {
381 mp_msg(MSGT_MUXER, MSGL_FATAL, "Invalid output format parameters\n"); 382 mp_msg(MSGT_MUXER, MSGL_FATAL, "invalid output format parameters\n");
382 goto fail; 383 goto fail;
383 } 384 }
384 priv->oc->packet_size= mux_packet_size; 385 priv->oc->packet_size= mux_packet_size;
385 priv->oc->mux_rate= mux_rate; 386 priv->oc->mux_rate= mux_rate;
386 priv->oc->preload= (int)(mux_preload*AV_TIME_BASE); 387 priv->oc->preload= (int)(mux_preload*AV_TIME_BASE);
396 if (info_comment) 397 if (info_comment)
397 av_strlcpy(priv->oc->comment , info_comment, sizeof(priv->oc->comment )); 398 av_strlcpy(priv->oc->comment , info_comment, sizeof(priv->oc->comment ));
398 399
399 if(mux_avopt){ 400 if(mux_avopt){
400 if(parse_avopts(priv->oc, mux_avopt) < 0){ 401 if(parse_avopts(priv->oc, mux_avopt) < 0){
401 mp_msg(MSGT_MUXER,MSGL_ERR, "Your options /%s/ look like gibberish to me pal\n", mux_avopt); 402 mp_msg(MSGT_MUXER,MSGL_ERR, "Your options /%s/ look like gibberish to me pal.\n", mux_avopt);
402 goto fail; 403 goto fail;
403 } 404 }
404 } 405 }
405 406
406 register_protocol(&mp_protocol); 407 register_protocol(&mp_protocol);
407 408
408 priv_data= muxer; 409 priv_data= muxer;
409 if(url_fopen(&priv->oc->pb, mp_filename, URL_WRONLY)) 410 if(url_fopen(&priv->oc->pb, mp_filename, URL_WRONLY))
410 { 411 {
411 mp_msg(MSGT_MUXER, MSGL_FATAL, "Could not open outfile\n"); 412 mp_msg(MSGT_MUXER, MSGL_FATAL, "Could not open outfile.\n");
412 goto fail; 413 goto fail;
413 } 414 }
414 415
415 muxer->priv = (void *) priv; 416 muxer->priv = (void *) priv;
416 muxer->cont_new_stream = &lavf_new_stream; 417 muxer->cont_new_stream = &lavf_new_stream;
417 muxer->cont_write_chunk = &write_chunk; 418 muxer->cont_write_chunk = &write_chunk;
418 muxer->cont_write_header = &write_header; 419 muxer->cont_write_header = &write_header;
419 muxer->cont_write_index = &write_trailer; 420 muxer->cont_write_index = &write_trailer;
420 muxer->fix_stream_parameters = &fix_parameters; 421 muxer->fix_stream_parameters = &fix_parameters;
421 mp_msg(MSGT_MUXER, MSGL_INFO, "OK, exit\n"); 422 mp_msg(MSGT_MUXER, MSGL_INFO, "OK, exit.\n");
422 return 1; 423 return 1;
423 424
424 fail: 425 fail:
425 free(priv); 426 free(priv);
426 return 0; 427 return 0;