~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/flvenc.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * License along with Libav; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
 
21
 
 
22
#include "libavutil/intfloat.h"
21
23
#include "avformat.h"
22
24
#include "flv.h"
23
25
#include "internal.h"
55
57
    int64_t duration_offset;
56
58
    int64_t filesize_offset;
57
59
    int64_t duration;
58
 
    int delay; ///< first dts delay for AVC
59
 
    int64_t last_video_ts;
 
60
    int64_t delay;      ///< first dts delay (needed for AVC & Speex)
60
61
} FLVContext;
61
62
 
 
63
typedef struct FLVStreamContext {
 
64
    int64_t last_ts;    ///< last timestamp for each stream
 
65
} FLVStreamContext;
 
66
 
62
67
static int get_audio_flags(AVCodecContext *enc){
63
68
    int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT;
64
69
 
73
78
            av_log(enc, AV_LOG_ERROR, "flv only supports mono Speex audio\n");
74
79
            return -1;
75
80
        }
76
 
        if (enc->frame_size / 320 > 8) {
77
 
            av_log(enc, AV_LOG_WARNING, "Warning: Speex stream has more than "
78
 
                                        "8 frames per packet. Adobe Flash "
79
 
                                        "Player cannot handle this!\n");
80
 
        }
81
81
        return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT;
82
82
    } else {
83
83
    switch (enc->sample_rate) {
90
90
        case    11025:
91
91
            flags |= FLV_SAMPLERATE_11025HZ;
92
92
            break;
 
93
        case    16000: //nellymoser only
93
94
        case     8000: //nellymoser only
94
95
        case     5512: //not mp3
95
96
            if(enc->codec_id != CODEC_ID_MP3){
125
126
    case CODEC_ID_NELLYMOSER:
126
127
        if (enc->sample_rate == 8000) {
127
128
            flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT;
 
129
        } else if (enc->sample_rate == 16000) {
 
130
            flags |= FLV_CODECID_NELLYMOSER_16KHZ_MONO | FLV_SAMPLESSIZE_16BIT;
128
131
        } else {
129
132
            flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT;
130
133
        }
162
165
static void put_amf_double(AVIOContext *pb, double d)
163
166
{
164
167
    avio_w8(pb, AMF_DATA_TYPE_NUMBER);
165
 
    avio_wb64(pb, av_dbl2int(d));
 
168
    avio_wb64(pb, av_double2int(d));
166
169
}
167
170
 
168
171
static void put_amf_bool(AVIOContext *pb, int b) {
175
178
    AVIOContext *pb = s->pb;
176
179
    FLVContext *flv = s->priv_data;
177
180
    AVCodecContext *audio_enc = NULL, *video_enc = NULL;
178
 
    int i;
 
181
    int i, metadata_count = 0;
179
182
    double framerate = 0.0;
180
 
    int metadata_size_pos, data_size;
 
183
    int64_t metadata_size_pos, data_size, metadata_count_pos;
181
184
    AVDictionaryEntry *tag = NULL;
182
185
 
183
186
    for(i=0; i<s->nb_streams; i++){
184
187
        AVCodecContext *enc = s->streams[i]->codec;
 
188
        FLVStreamContext *sc;
185
189
        if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
186
190
            if (s->streams[i]->r_frame_rate.den && s->streams[i]->r_frame_rate.num) {
187
191
                framerate = av_q2d(s->streams[i]->r_frame_rate);
198
202
            if(get_audio_flags(enc)<0)
199
203
                return -1;
200
204
        }
201
 
        av_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */
 
205
        avpriv_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */
 
206
 
 
207
        sc = av_mallocz(sizeof(FLVStreamContext));
 
208
        if (!sc)
 
209
            return AVERROR(ENOMEM);
 
210
        s->streams[i]->priv_data = sc;
 
211
        sc->last_ts = -1;
202
212
    }
 
213
    flv->delay = AV_NOPTS_VALUE;
 
214
 
203
215
    avio_write(pb, "FLV", 3);
204
216
    avio_w8(pb,1);
205
217
    avio_w8(pb,   FLV_HEADER_FLAG_HASAUDIO * !!audio_enc
218
230
        }
219
231
    }
220
232
 
221
 
    flv->last_video_ts = -1;
222
 
 
223
233
    /* write meta_tag */
224
234
    avio_w8(pb, 18);         // tag type META
225
235
    metadata_size_pos= avio_tell(pb);
235
245
 
236
246
    /* mixed array (hash) with size and string/type/data tuples */
237
247
    avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
238
 
    avio_wb32(pb, 5*!!video_enc + 5*!!audio_enc + 2); // +2 for duration and file size
 
248
    metadata_count_pos = avio_tell(pb);
 
249
    metadata_count = 5*!!video_enc + 5*!!audio_enc + 2; // +2 for duration and file size
 
250
    avio_wb32(pb, metadata_count);
239
251
 
240
252
    put_amf_string(pb, "duration");
241
253
    flv->duration_offset= avio_tell(pb);
279
291
        put_amf_string(pb, tag->key);
280
292
        avio_w8(pb, AMF_DATA_TYPE_STRING);
281
293
        put_amf_string(pb, tag->value);
 
294
        metadata_count++;
282
295
    }
283
296
 
284
297
    put_amf_string(pb, "filesize");
290
303
 
291
304
    /* write total size of tag */
292
305
    data_size= avio_tell(pb) - metadata_size_pos - 10;
 
306
 
 
307
    avio_seek(pb, metadata_count_pos, SEEK_SET);
 
308
    avio_wb32(pb, metadata_count);
 
309
 
293
310
    avio_seek(pb, metadata_size_pos, SEEK_SET);
294
311
    avio_wb24(pb, data_size);
295
312
    avio_skip(pb, data_size + 10 - 3);
338
355
    /* Add EOS tag */
339
356
    for (i = 0; i < s->nb_streams; i++) {
340
357
        AVCodecContext *enc = s->streams[i]->codec;
 
358
        FLVStreamContext *sc = s->streams[i]->priv_data;
341
359
        if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
342
360
                enc->codec_id == CODEC_ID_H264) {
343
 
            put_avc_eos_tag(pb, flv->last_video_ts);
 
361
            put_avc_eos_tag(pb, sc->last_ts);
344
362
        }
345
363
    }
346
364
 
347
365
    file_size = avio_tell(pb);
348
366
 
349
 
    /* update informations */
 
367
    /* update information */
350
368
    avio_seek(pb, flv->duration_offset, SEEK_SET);
351
369
    put_amf_double(pb, flv->duration / (double)1000);
352
370
    avio_seek(pb, flv->filesize_offset, SEEK_SET);
361
379
    AVIOContext *pb = s->pb;
362
380
    AVCodecContext *enc = s->streams[pkt->stream_index]->codec;
363
381
    FLVContext *flv = s->priv_data;
 
382
    FLVStreamContext *sc = s->streams[pkt->stream_index]->priv_data;
364
383
    unsigned ts;
365
384
    int size= pkt->size;
366
385
    uint8_t *data= NULL;
396
415
    }
397
416
 
398
417
    if (enc->codec_id == CODEC_ID_H264) {
399
 
        /* check if extradata looks like mp4 formated */
 
418
        /* check if extradata looks like MP4 */
400
419
        if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
401
420
            if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0)
402
421
                return -1;
403
422
        }
404
 
        if (!flv->delay && pkt->dts < 0)
405
 
            flv->delay = -pkt->dts;
 
423
    }
 
424
    if (flv->delay == AV_NOPTS_VALUE)
 
425
        flv->delay = -pkt->dts;
 
426
    if (pkt->dts < -flv->delay) {
 
427
        av_log(s, AV_LOG_WARNING, "Packets are not in the proper order with "
 
428
                                  "respect to DTS\n");
 
429
        return AVERROR(EINVAL);
406
430
    }
407
431
 
408
432
    ts = pkt->dts + flv->delay; // add delay to force positive dts
409
 
    if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
410
 
        if (flv->last_video_ts < ts)
411
 
            flv->last_video_ts = ts;
 
433
 
 
434
    /* check Speex packet duration */
 
435
    if (enc->codec_id == CODEC_ID_SPEEX && ts - sc->last_ts > 160) {
 
436
        av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than "
 
437
                                  "8 frames per packet. Adobe Flash "
 
438
                                  "Player cannot handle this!\n");
412
439
    }
 
440
 
 
441
    if (sc->last_ts < ts)
 
442
        sc->last_ts = ts;
 
443
 
413
444
    avio_wb24(pb,size + flags_size);
414
445
    avio_wb24(pb,ts);
415
446
    avio_w8(pb,(ts >> 24) & 0x7F); // timestamps are 32bits _signed_
439
470
}
440
471
 
441
472
AVOutputFormat ff_flv_muxer = {
442
 
    "flv",
443
 
    NULL_IF_CONFIG_SMALL("FLV format"),
444
 
    "video/x-flv",
445
 
    "flv",
446
 
    sizeof(FLVContext),
 
473
    .name           = "flv",
 
474
    .long_name      = NULL_IF_CONFIG_SMALL("FLV format"),
 
475
    .mime_type      = "video/x-flv",
 
476
    .extensions     = "flv",
 
477
    .priv_data_size = sizeof(FLVContext),
447
478
#if CONFIG_LIBMP3LAME
448
 
    CODEC_ID_MP3,
 
479
    .audio_codec    = CODEC_ID_MP3,
449
480
#else // CONFIG_LIBMP3LAME
450
 
    CODEC_ID_ADPCM_SWF,
 
481
    .audio_codec    = CODEC_ID_ADPCM_SWF,
451
482
#endif // CONFIG_LIBMP3LAME
452
 
    CODEC_ID_FLV1,
453
 
    flv_write_header,
454
 
    flv_write_packet,
455
 
    flv_write_trailer,
 
483
    .video_codec    = CODEC_ID_FLV1,
 
484
    .write_header   = flv_write_header,
 
485
    .write_packet   = flv_write_packet,
 
486
    .write_trailer  = flv_write_trailer,
456
487
    .codec_tag= (const AVCodecTag* const []){flv_video_codec_ids, flv_audio_codec_ids, 0},
457
488
    .flags= AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
458
489
};