*/
#include "libavutil/intreadwrite.h"
-#include "libavutil/intfloat_readwrite.h"
+#include "libavutil/intfloat.h"
#include "avformat.h"
#include "flv.h"
#include "internal.h"
int64_t duration_offset;
int64_t filesize_offset;
int64_t duration;
+ int64_t delay; ///< first dts delay (needed for AVC & Speex)
} FLVContext;
typedef struct FLVStreamContext {
- int delay; ///< first dts delay for each stream (needed for AVC & Speex)
int64_t last_ts; ///< last timestamp for each stream
} FLVStreamContext;
case 11025:
flags |= FLV_SAMPLERATE_11025HZ;
break;
+ case 16000: //nellymoser only
case 8000: //nellymoser only
case 5512: //not mp3
if(enc->codec_id != CODEC_ID_MP3){
case CODEC_ID_NELLYMOSER:
if (enc->sample_rate == 8000) {
flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT;
+ } else if (enc->sample_rate == 16000) {
+ flags |= FLV_CODECID_NELLYMOSER_16KHZ_MONO | FLV_SAMPLESSIZE_16BIT;
} else {
flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT;
}
static void put_amf_double(AVIOContext *pb, double d)
{
avio_w8(pb, AMF_DATA_TYPE_NUMBER);
- avio_wb64(pb, av_dbl2int(d));
+ avio_wb64(pb, av_double2int(d));
}
static void put_amf_bool(AVIOContext *pb, int b) {
if(get_audio_flags(enc)<0)
return -1;
}
- av_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */
+ avpriv_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */
sc = av_mallocz(sizeof(FLVStreamContext));
if (!sc)
s->streams[i]->priv_data = sc;
sc->last_ts = -1;
}
+ flv->delay = AV_NOPTS_VALUE;
+
avio_write(pb, "FLV", 3);
avio_w8(pb,1);
avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!audio_enc
file_size = avio_tell(pb);
- /* update informations */
+ /* update information */
avio_seek(pb, flv->duration_offset, SEEK_SET);
put_amf_double(pb, flv->duration / (double)1000);
avio_seek(pb, flv->filesize_offset, SEEK_SET);
assert(enc->codec_type == AVMEDIA_TYPE_DATA);
avio_w8(pb, FLV_TAG_TYPE_META);
flags_size = 0;
- flags = NULL;
+ flags = 0;
}
if (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) {
av_log(s, AV_LOG_ERROR, "malformated aac bitstream, use -absf aac_adtstoasc\n");
return -1;
}
- if (!sc->delay && pkt->dts < 0)
- sc->delay = -pkt->dts;
+ if (flv->delay == AV_NOPTS_VALUE)
+ flv->delay = -pkt->dts;
+ if (pkt->dts < -flv->delay) {
+ av_log(s, AV_LOG_WARNING, "Packets are not in the proper order with "
+ "respect to DTS\n");
+ return AVERROR(EINVAL);
+ }
- ts = pkt->dts + sc->delay; // add delay to force positive dts
+ ts = pkt->dts + flv->delay; // add delay to force positive dts
/* check Speex packet duration */
if (enc->codec_id == CODEC_ID_SPEEX && ts - sc->last_ts > 160) {
avio_write(pb, data ? data : pkt->data, size);
avio_wb32(pb,size+flags_size+11); // previous tag size
- flv->duration = FFMAX(flv->duration, pkt->pts + sc->delay + pkt->duration);
+ flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration);
avio_flush(pb);