00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "avformat.h"
00023 #include "bitstream.h"
00024 #include "riff.h"
00025
00026
00027 #define DUMMY_FILE_SIZE (100 * 1024 * 1024)
00028 #define DUMMY_DURATION 600
00029
00030 #define TAG_END 0
00031 #define TAG_SHOWFRAME 1
00032 #define TAG_DEFINESHAPE 2
00033 #define TAG_FREECHARACTER 3
00034 #define TAG_PLACEOBJECT 4
00035 #define TAG_REMOVEOBJECT 5
00036 #define TAG_STREAMHEAD 18
00037 #define TAG_STREAMBLOCK 19
00038 #define TAG_JPEG2 21
00039 #define TAG_PLACEOBJECT2 26
00040 #define TAG_STREAMHEAD2 45
00041 #define TAG_VIDEOSTREAM 60
00042 #define TAG_VIDEOFRAME 61
00043
00044 #define TAG_LONG 0x100
00045
00046
00047 #define FLAG_MOVETO 0x01
00048 #define FLAG_SETFILL0 0x02
00049 #define FLAG_SETFILL1 0x04
00050
00051 #define AUDIO_FIFO_SIZE 65536
00052
00053
00054 #define BITMAP_ID 0
00055 #define VIDEO_ID 0
00056 #define SHAPE_ID 1
00057
00058 #undef NDEBUG
00059 #include <assert.h>
00060
00061 typedef struct {
00062 int audio_stream_index;
00063 offset_t duration_pos;
00064 offset_t tag_pos;
00065
00066 int samples_per_frame;
00067 int sound_samples;
00068 int swf_frame_number;
00069 int video_frame_number;
00070 int frame_rate;
00071 int tag;
00072
00073 uint8_t audio_fifo[AUDIO_FIFO_SIZE];
00074 int audio_in_pos;
00075
00076 int video_type;
00077 int audio_type;
00078 } SWFContext;
00079
00080 static const AVCodecTag swf_codec_tags[] = {
00081 {CODEC_ID_FLV1, 0x02},
00082 {CODEC_ID_VP6F, 0x04},
00083 {0, 0},
00084 };
00085
00086 static const AVCodecTag swf_audio_codec_tags[] = {
00087 {CODEC_ID_PCM_S16LE, 0x00},
00088 {CODEC_ID_ADPCM_SWF, 0x01},
00089 {CODEC_ID_MP3, 0x02},
00090 {CODEC_ID_PCM_S16LE, 0x03},
00091
00092 {0, 0},
00093 };
00094
00095 #ifdef CONFIG_MUXERS
00096 static void put_swf_tag(AVFormatContext *s, int tag)
00097 {
00098 SWFContext *swf = s->priv_data;
00099 ByteIOContext *pb = &s->pb;
00100
00101 swf->tag_pos = url_ftell(pb);
00102 swf->tag = tag;
00103
00104 if (tag & TAG_LONG) {
00105 put_le16(pb, 0);
00106 put_le32(pb, 0);
00107 } else {
00108 put_le16(pb, 0);
00109 }
00110 }
00111
00112 static void put_swf_end_tag(AVFormatContext *s)
00113 {
00114 SWFContext *swf = s->priv_data;
00115 ByteIOContext *pb = &s->pb;
00116 offset_t pos;
00117 int tag_len, tag;
00118
00119 pos = url_ftell(pb);
00120 tag_len = pos - swf->tag_pos - 2;
00121 tag = swf->tag;
00122 url_fseek(pb, swf->tag_pos, SEEK_SET);
00123 if (tag & TAG_LONG) {
00124 tag &= ~TAG_LONG;
00125 put_le16(pb, (tag << 6) | 0x3f);
00126 put_le32(pb, tag_len - 4);
00127 } else {
00128 assert(tag_len < 0x3f);
00129 put_le16(pb, (tag << 6) | tag_len);
00130 }
00131 url_fseek(pb, pos, SEEK_SET);
00132 }
00133
00134 static inline void max_nbits(int *nbits_ptr, int val)
00135 {
00136 int n;
00137
00138 if (val == 0)
00139 return;
00140 val = abs(val);
00141 n = 1;
00142 while (val != 0) {
00143 n++;
00144 val >>= 1;
00145 }
00146 if (n > *nbits_ptr)
00147 *nbits_ptr = n;
00148 }
00149
00150 static void put_swf_rect(ByteIOContext *pb,
00151 int xmin, int xmax, int ymin, int ymax)
00152 {
00153 PutBitContext p;
00154 uint8_t buf[256];
00155 int nbits, mask;
00156
00157 init_put_bits(&p, buf, sizeof(buf));
00158
00159 nbits = 0;
00160 max_nbits(&nbits, xmin);
00161 max_nbits(&nbits, xmax);
00162 max_nbits(&nbits, ymin);
00163 max_nbits(&nbits, ymax);
00164 mask = (1 << nbits) - 1;
00165
00166
00167 put_bits(&p, 5, nbits);
00168 put_bits(&p, nbits, xmin & mask);
00169 put_bits(&p, nbits, xmax & mask);
00170 put_bits(&p, nbits, ymin & mask);
00171 put_bits(&p, nbits, ymax & mask);
00172
00173 flush_put_bits(&p);
00174 put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
00175 }
00176
00177 static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
00178 {
00179 int nbits, mask;
00180
00181 put_bits(pb, 1, 1);
00182 put_bits(pb, 1, 1);
00183 nbits = 2;
00184 max_nbits(&nbits, dx);
00185 max_nbits(&nbits, dy);
00186
00187 mask = (1 << nbits) - 1;
00188 put_bits(pb, 4, nbits - 2);
00189 if (dx == 0) {
00190 put_bits(pb, 1, 0);
00191 put_bits(pb, 1, 1);
00192 put_bits(pb, nbits, dy & mask);
00193 } else if (dy == 0) {
00194 put_bits(pb, 1, 0);
00195 put_bits(pb, 1, 0);
00196 put_bits(pb, nbits, dx & mask);
00197 } else {
00198 put_bits(pb, 1, 1);
00199 put_bits(pb, nbits, dx & mask);
00200 put_bits(pb, nbits, dy & mask);
00201 }
00202 }
00203
00204 #define FRAC_BITS 16
00205
00206
00207 static void put_swf_matrix(ByteIOContext *pb,
00208 int a, int b, int c, int d, int tx, int ty)
00209 {
00210 PutBitContext p;
00211 uint8_t buf[256];
00212 int nbits;
00213
00214 init_put_bits(&p, buf, sizeof(buf));
00215
00216 put_bits(&p, 1, 1);
00217 nbits = 1;
00218 max_nbits(&nbits, a);
00219 max_nbits(&nbits, d);
00220 put_bits(&p, 5, nbits);
00221 put_bits(&p, nbits, a);
00222 put_bits(&p, nbits, d);
00223
00224 put_bits(&p, 1, 1);
00225 nbits = 1;
00226 max_nbits(&nbits, c);
00227 max_nbits(&nbits, b);
00228 put_bits(&p, 5, nbits);
00229 put_bits(&p, nbits, c);
00230 put_bits(&p, nbits, b);
00231
00232 nbits = 1;
00233 max_nbits(&nbits, tx);
00234 max_nbits(&nbits, ty);
00235 put_bits(&p, 5, nbits);
00236 put_bits(&p, nbits, tx);
00237 put_bits(&p, nbits, ty);
00238
00239 flush_put_bits(&p);
00240 put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
00241 }
00242
00243
00244 static int swf_write_header(AVFormatContext *s)
00245 {
00246 SWFContext *swf = s->priv_data;
00247 ByteIOContext *pb = &s->pb;
00248 AVCodecContext *enc, *audio_enc, *video_enc;
00249 PutBitContext p;
00250 uint8_t buf1[256];
00251 int i, width, height, rate, rate_base;
00252
00253 swf->audio_in_pos = 0;
00254 swf->sound_samples = 0;
00255 swf->swf_frame_number = 0;
00256 swf->video_frame_number = 0;
00257
00258 video_enc = NULL;
00259 audio_enc = NULL;
00260 for(i=0;i<s->nb_streams;i++) {
00261 enc = s->streams[i]->codec;
00262 if (enc->codec_type == CODEC_TYPE_AUDIO) {
00263 if (enc->codec_id == CODEC_ID_MP3) {
00264 if (!enc->frame_size) {
00265 av_log(s, AV_LOG_ERROR, "audio frame size not set\n");
00266 return -1;
00267 }
00268 audio_enc = enc;
00269 } else {
00270 av_log(s, AV_LOG_ERROR, "SWF muxer only supports MP3\n");
00271 return -1;
00272 }
00273 } else {
00274 if (enc->codec_id == CODEC_ID_VP6F ||
00275 enc->codec_id == CODEC_ID_FLV1 ||
00276 enc->codec_id == CODEC_ID_MJPEG) {
00277 video_enc = enc;
00278 } else {
00279 av_log(s, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV1 and MJPEG\n");
00280 return -1;
00281 }
00282 }
00283 }
00284
00285 if (!video_enc) {
00286
00287 swf->video_type = 0;
00288 width = 320;
00289 height = 200;
00290 rate = 10;
00291 rate_base= 1;
00292 } else {
00293 swf->video_type = video_enc->codec_id;
00294 width = video_enc->width;
00295 height = video_enc->height;
00296 rate = video_enc->time_base.den;
00297 rate_base = video_enc->time_base.num;
00298 }
00299
00300 if (!audio_enc) {
00301 swf->audio_type = 0;
00302 swf->samples_per_frame = (44100. * rate_base) / rate;
00303 } else {
00304 swf->audio_type = audio_enc->codec_id;
00305 swf->samples_per_frame = (audio_enc->sample_rate * rate_base) / rate;
00306 }
00307
00308 put_tag(pb, "FWS");
00309 if (video_enc && video_enc->codec_id == CODEC_ID_VP6F) {
00310 put_byte(pb, 8);
00311 } else if (video_enc && video_enc->codec_id == CODEC_ID_FLV1) {
00312 put_byte(pb, 6);
00313 } else {
00314 put_byte(pb, 4);
00315 }
00316 put_le32(pb, DUMMY_FILE_SIZE);
00317
00318
00319 put_swf_rect(pb, 0, width * 20, 0, height * 20);
00320 put_le16(pb, (rate * 256) / rate_base);
00321 swf->duration_pos = url_ftell(pb);
00322 put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base));
00323
00324
00325 if (video_enc && (video_enc->codec_id == CODEC_ID_VP6F ||
00326 video_enc->codec_id == CODEC_ID_FLV1)) {
00327 } else if (video_enc && video_enc->codec_id == CODEC_ID_MJPEG) {
00328 put_swf_tag(s, TAG_DEFINESHAPE);
00329
00330 put_le16(pb, SHAPE_ID);
00331
00332 put_swf_rect(pb, 0, width, 0, height);
00333
00334 put_byte(pb, 1);
00335 put_byte(pb, 0x41);
00336 put_le16(pb, BITMAP_ID);
00337
00338 put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0,
00339 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0);
00340 put_byte(pb, 0);
00341
00342
00343 init_put_bits(&p, buf1, sizeof(buf1));
00344 put_bits(&p, 4, 1);
00345 put_bits(&p, 4, 0);
00346
00347 put_bits(&p, 1, 0);
00348 put_bits(&p, 5, FLAG_MOVETO | FLAG_SETFILL0);
00349 put_bits(&p, 5, 1);
00350 put_bits(&p, 1, 0);
00351 put_bits(&p, 1, 0);
00352 put_bits(&p, 1, 1);
00353
00354
00355 put_swf_line_edge(&p, width, 0);
00356 put_swf_line_edge(&p, 0, height);
00357 put_swf_line_edge(&p, -width, 0);
00358 put_swf_line_edge(&p, 0, -height);
00359
00360
00361 put_bits(&p, 1, 0);
00362 put_bits(&p, 5, 0);
00363
00364 flush_put_bits(&p);
00365 put_buffer(pb, buf1, pbBufPtr(&p) - p.buf);
00366
00367 put_swf_end_tag(s);
00368 }
00369
00370 if (audio_enc && audio_enc->codec_id == CODEC_ID_MP3) {
00371 int v;
00372
00373
00374 put_swf_tag(s, TAG_STREAMHEAD2);
00375
00376 v = 0;
00377 switch(audio_enc->sample_rate) {
00378 case 11025:
00379 v |= 1 << 2;
00380 break;
00381 case 22050:
00382 v |= 2 << 2;
00383 break;
00384 case 44100:
00385 v |= 3 << 2;
00386 break;
00387 default:
00388
00389 av_log(s, AV_LOG_ERROR, "swf does not support that sample rate, choose from (44100, 22050, 11025).\n");
00390 return -1;
00391 }
00392 v |= 0x02;
00393 if (audio_enc->channels == 2)
00394 v |= 0x01;
00395 put_byte(&s->pb, v);
00396 v |= 0x20;
00397 put_byte(&s->pb, v);
00398 put_le16(&s->pb, swf->samples_per_frame);
00399 put_le16(&s->pb, 0);
00400
00401 put_swf_end_tag(s);
00402 }
00403
00404 put_flush_packet(&s->pb);
00405 return 0;
00406 }
00407
00408 static int swf_write_video(AVFormatContext *s,
00409 AVCodecContext *enc, const uint8_t *buf, int size)
00410 {
00411 SWFContext *swf = s->priv_data;
00412 ByteIOContext *pb = &s->pb;
00413
00414
00415 if (swf->swf_frame_number == 16000) {
00416 av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
00417 }
00418
00419 if (swf->video_type == CODEC_ID_VP6F ||
00420 swf->video_type == CODEC_ID_FLV1) {
00421 if (swf->video_frame_number == 0) {
00422
00423 put_swf_tag(s, TAG_VIDEOSTREAM);
00424 put_le16(pb, VIDEO_ID);
00425 put_le16(pb, 15000);
00426 put_le16(pb, enc->width);
00427 put_le16(pb, enc->height);
00428 put_byte(pb, 0);
00429 put_byte(pb,codec_get_tag(swf_codec_tags,swf->video_type));
00430 put_swf_end_tag(s);
00431
00432
00433 put_swf_tag(s, TAG_PLACEOBJECT2);
00434 put_byte(pb, 0x36);
00435 put_le16(pb, 1);
00436 put_le16(pb, VIDEO_ID);
00437 put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0);
00438 put_le16(pb, swf->video_frame_number);
00439 put_byte(pb, 'v');
00440 put_byte(pb, 'i');
00441 put_byte(pb, 'd');
00442 put_byte(pb, 'e');
00443 put_byte(pb, 'o');
00444 put_byte(pb, 0x00);
00445 put_swf_end_tag(s);
00446 } else {
00447
00448 put_swf_tag(s, TAG_PLACEOBJECT2);
00449 put_byte(pb, 0x11);
00450 put_le16(pb, 1);
00451 put_le16(pb, swf->video_frame_number);
00452 put_swf_end_tag(s);
00453 }
00454
00455
00456 put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG);
00457 put_le16(pb, VIDEO_ID);
00458 put_le16(pb, swf->video_frame_number++);
00459 put_buffer(pb, buf, size);
00460 put_swf_end_tag(s);
00461 } else if (swf->video_type == CODEC_ID_MJPEG) {
00462 if (swf->swf_frame_number > 0) {
00463
00464 put_swf_tag(s, TAG_REMOVEOBJECT);
00465 put_le16(pb, SHAPE_ID);
00466 put_le16(pb, 1);
00467 put_swf_end_tag(s);
00468
00469
00470 put_swf_tag(s, TAG_FREECHARACTER);
00471 put_le16(pb, BITMAP_ID);
00472 put_swf_end_tag(s);
00473 }
00474
00475 put_swf_tag(s, TAG_JPEG2 | TAG_LONG);
00476
00477 put_le16(pb, BITMAP_ID);
00478
00479
00480 put_byte(pb, 0xff);
00481 put_byte(pb, 0xd8);
00482 put_byte(pb, 0xff);
00483 put_byte(pb, 0xd9);
00484
00485 put_buffer(pb, buf, size);
00486
00487 put_swf_end_tag(s);
00488
00489
00490
00491 put_swf_tag(s, TAG_PLACEOBJECT);
00492 put_le16(pb, SHAPE_ID);
00493 put_le16(pb, 1);
00494 put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0);
00495 put_swf_end_tag(s);
00496 } else {
00497
00498 }
00499
00500 swf->swf_frame_number ++;
00501
00502
00503 if (swf->audio_type && swf->audio_in_pos) {
00504 put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
00505 put_le16(pb, swf->sound_samples);
00506 put_le16(pb, 0);
00507 put_buffer(pb, swf->audio_fifo, swf->audio_in_pos);
00508 put_swf_end_tag(s);
00509
00510
00511 swf->sound_samples = 0;
00512 swf->audio_in_pos = 0;
00513 }
00514
00515
00516 put_swf_tag(s, TAG_SHOWFRAME);
00517 put_swf_end_tag(s);
00518
00519 put_flush_packet(&s->pb);
00520
00521 return 0;
00522 }
00523
00524 static int swf_write_audio(AVFormatContext *s,
00525 AVCodecContext *enc, const uint8_t *buf, int size)
00526 {
00527 SWFContext *swf = s->priv_data;
00528
00529
00530 if (swf->swf_frame_number == 16000) {
00531 av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
00532 }
00533
00534 if (swf->audio_in_pos + size >= AUDIO_FIFO_SIZE) {
00535 av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
00536 return -1;
00537 }
00538
00539 memcpy(swf->audio_fifo + swf->audio_in_pos, buf, size);
00540 swf->audio_in_pos += size;
00541 swf->sound_samples += enc->frame_size;
00542
00543
00544 if (swf->video_type == 0) {
00545 swf_write_video(s, enc, 0, 0);
00546 }
00547
00548 return 0;
00549 }
00550
00551 static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
00552 {
00553 AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
00554 if (codec->codec_type == CODEC_TYPE_AUDIO)
00555 return swf_write_audio(s, codec, pkt->data, pkt->size);
00556 else
00557 return swf_write_video(s, codec, pkt->data, pkt->size);
00558 }
00559
00560 static int swf_write_trailer(AVFormatContext *s)
00561 {
00562 SWFContext *swf = s->priv_data;
00563 ByteIOContext *pb = &s->pb;
00564 AVCodecContext *enc, *video_enc;
00565 int file_size, i;
00566
00567 video_enc = NULL;
00568 for(i=0;i<s->nb_streams;i++) {
00569 enc = s->streams[i]->codec;
00570 if (enc->codec_type == CODEC_TYPE_VIDEO)
00571 video_enc = enc;
00572 }
00573
00574 put_swf_tag(s, TAG_END);
00575 put_swf_end_tag(s);
00576
00577 put_flush_packet(&s->pb);
00578
00579
00580 if (!url_is_streamed(&s->pb) && video_enc) {
00581 file_size = url_ftell(pb);
00582 url_fseek(pb, 4, SEEK_SET);
00583 put_le32(pb, file_size);
00584 url_fseek(pb, swf->duration_pos, SEEK_SET);
00585 put_le16(pb, video_enc->frame_number);
00586 url_fseek(pb, file_size, SEEK_SET);
00587 }
00588 return 0;
00589 }
00590 #endif //CONFIG_MUXERS
00591
00592
00593
00594
00595
00596
00597
00598
00599 static int get_swf_tag(ByteIOContext *pb, int *len_ptr)
00600 {
00601 int tag, len;
00602
00603 if (url_feof(pb))
00604 return -1;
00605
00606 tag = get_le16(pb);
00607 len = tag & 0x3f;
00608 tag = tag >> 6;
00609 if (len == 0x3f) {
00610 len = get_le32(pb);
00611 }
00612
00613 *len_ptr = len;
00614 return tag;
00615 }
00616
00617
00618 static int swf_probe(AVProbeData *p)
00619 {
00620
00621 if ((p->buf[0] == 'F' || p->buf[0] == 'C') && p->buf[1] == 'W' &&
00622 p->buf[2] == 'S')
00623 return AVPROBE_SCORE_MAX;
00624 else
00625 return 0;
00626 }
00627
00628 static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
00629 {
00630 SWFContext *swf = s->priv_data;
00631 ByteIOContext *pb = &s->pb;
00632 int nbits, len, tag;
00633
00634 tag = get_be32(pb) & 0xffffff00;
00635
00636 if (tag == MKBETAG('C', 'W', 'S', 0)) {
00637 av_log(s, AV_LOG_ERROR, "Compressed SWF format not supported\n");
00638 return AVERROR(EIO);
00639 }
00640 if (tag != MKBETAG('F', 'W', 'S', 0))
00641 return AVERROR(EIO);
00642 get_le32(pb);
00643
00644 nbits = get_byte(pb) >> 3;
00645 len = (4 * nbits - 3 + 7) / 8;
00646 url_fskip(pb, len);
00647 swf->frame_rate = get_le16(pb);
00648 get_le16(pb);
00649
00650 swf->samples_per_frame = 0;
00651 s->ctx_flags |= AVFMTCTX_NOHEADER;
00652 return 0;
00653 }
00654
00655 static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
00656 {
00657 SWFContext *swf = s->priv_data;
00658 ByteIOContext *pb = &s->pb;
00659 AVStream *vst = NULL, *ast = NULL, *st = 0;
00660 int tag, len, i, frame, v;
00661
00662 for(;;) {
00663 tag = get_swf_tag(pb, &len);
00664 if (tag < 0)
00665 return AVERROR(EIO);
00666 if (tag == TAG_VIDEOSTREAM && !vst) {
00667 int ch_id = get_le16(pb);
00668 get_le16(pb);
00669 get_le16(pb);
00670 get_le16(pb);
00671 get_byte(pb);
00672
00673 vst = av_new_stream(s, ch_id);
00674 vst->codec->codec_type = CODEC_TYPE_VIDEO;
00675 vst->codec->codec_id = codec_get_id(swf_codec_tags, get_byte(pb));
00676 av_set_pts_info(vst, 64, 256, swf->frame_rate);
00677 vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
00678 len -= 10;
00679 } else if ((tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) && !ast) {
00680
00681 int sample_rate_code;
00682 get_byte(pb);
00683 v = get_byte(pb);
00684 swf->samples_per_frame = get_le16(pb);
00685 ast = av_new_stream(s, -1);
00686 swf->audio_stream_index = ast->index;
00687 ast->codec->channels = 1 + (v&1);
00688 ast->codec->codec_type = CODEC_TYPE_AUDIO;
00689 ast->codec->codec_id = codec_get_id(swf_audio_codec_tags, (v>>4) & 15);
00690 ast->need_parsing = AVSTREAM_PARSE_FULL;
00691 sample_rate_code= (v>>2) & 3;
00692 if (!sample_rate_code)
00693 return AVERROR(EIO);
00694 ast->codec->sample_rate = 11025 << (sample_rate_code-1);
00695 av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
00696 len -= 4;
00697 } else if (tag == TAG_VIDEOFRAME) {
00698 int ch_id = get_le16(pb);
00699 len -= 2;
00700 for(i=0; i<s->nb_streams; i++) {
00701 st = s->streams[i];
00702 if (st->codec->codec_type == CODEC_TYPE_VIDEO && st->id == ch_id) {
00703 frame = get_le16(pb);
00704 av_get_packet(pb, pkt, len-2);
00705 pkt->pts = frame;
00706 pkt->stream_index = st->index;
00707 return pkt->size;
00708 }
00709 }
00710 } else if (tag == TAG_STREAMBLOCK) {
00711 st = s->streams[swf->audio_stream_index];
00712 if (st->codec->codec_id == CODEC_ID_MP3) {
00713 url_fskip(pb, 4);
00714 av_get_packet(pb, pkt, len-4);
00715 } else {
00716 av_get_packet(pb, pkt, len);
00717 }
00718 pkt->stream_index = st->index;
00719 return pkt->size;
00720 } else if (tag == TAG_JPEG2) {
00721 for (i=0; i<s->nb_streams; i++) {
00722 st = s->streams[i];
00723 if (st->id == -2)
00724 break;
00725 }
00726 if (i == s->nb_streams) {
00727 vst = av_new_stream(s, -2);
00728 vst->codec->codec_type = CODEC_TYPE_VIDEO;
00729 vst->codec->codec_id = CODEC_ID_MJPEG;
00730 av_set_pts_info(vst, 64, 256, swf->frame_rate);
00731 vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
00732 st = vst;
00733 }
00734 get_le16(pb);
00735 av_new_packet(pkt, len-2);
00736 get_buffer(pb, pkt->data, 4);
00737 if (AV_RB32(pkt->data) == 0xffd8ffd9 ||
00738 AV_RB32(pkt->data) == 0xffd9ffd8) {
00739
00740
00741 pkt->size -= 4;
00742 get_buffer(pb, pkt->data, pkt->size);
00743 } else {
00744 get_buffer(pb, pkt->data + 4, pkt->size - 4);
00745 }
00746 pkt->stream_index = st->index;
00747 return pkt->size;
00748 }
00749 url_fskip(pb, len);
00750 }
00751 return 0;
00752 }
00753
00754 static int swf_read_close(AVFormatContext *s)
00755 {
00756 return 0;
00757 }
00758
00759 #ifdef CONFIG_SWF_DEMUXER
00760 AVInputFormat swf_demuxer = {
00761 "swf",
00762 "Flash format",
00763 sizeof(SWFContext),
00764 swf_probe,
00765 swf_read_header,
00766 swf_read_packet,
00767 swf_read_close,
00768 };
00769 #endif
00770 #ifdef CONFIG_SWF_MUXER
00771 AVOutputFormat swf_muxer = {
00772 "swf",
00773 "Flash format",
00774 "application/x-shockwave-flash",
00775 "swf",
00776 sizeof(SWFContext),
00777 CODEC_ID_MP3,
00778 CODEC_ID_FLV1,
00779 swf_write_header,
00780 swf_write_packet,
00781 swf_write_trailer,
00782 };
00783 #endif