| 803 | } |
| 804 | |
| 805 | static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, int64_t ts, int stream_index) { |
| 806 | int64_t data_size; |
| 807 | AVIOContext *pb = s->pb; |
| 808 | FLVContext *flv = s->priv_data; |
| 809 | int track_idx = flv->track_idx_map[stream_index]; |
| 810 | int extended_flv = 0; |
| 811 | |
| 812 | if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264 |
| 813 | || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC |
| 814 | || par->codec_id == AV_CODEC_ID_AV1 || par->codec_id == AV_CODEC_ID_VP9 |
| 815 | || par->codec_id == AV_CODEC_ID_VVC |
| 816 | || (par->codec_id == AV_CODEC_ID_MP3 && track_idx) |
| 817 | || par->codec_id == AV_CODEC_ID_OPUS || par->codec_id == AV_CODEC_ID_FLAC |
| 818 | || par->codec_id == AV_CODEC_ID_AC3 || par->codec_id == AV_CODEC_ID_EAC3) { |
| 819 | int64_t pos; |
| 820 | avio_w8(pb, |
| 821 | par->codec_type == AVMEDIA_TYPE_VIDEO ? |
| 822 | FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO); |
| 823 | avio_wb24(pb, 0); // size patched later |
| 824 | put_timestamp(pb, ts); |
| 825 | avio_wb24(pb, 0); // streamid |
| 826 | pos = avio_tell(pb); |
| 827 | if (par->codec_type == AVMEDIA_TYPE_AUDIO) { |
| 828 | extended_flv = (par->codec_id == AV_CODEC_ID_AAC && track_idx) |
| 829 | || (par->codec_id == AV_CODEC_ID_MP3 && track_idx) |
| 830 | || par->codec_id == AV_CODEC_ID_OPUS |
| 831 | || par->codec_id == AV_CODEC_ID_FLAC |
| 832 | || par->codec_id == AV_CODEC_ID_AC3 |
| 833 | || par->codec_id == AV_CODEC_ID_EAC3; |
| 834 | |
| 835 | if (extended_flv) { |
| 836 | if (track_idx) { |
| 837 | avio_w8(pb, FLV_CODECID_EX_HEADER | AudioPacketTypeMultitrack); |
| 838 | avio_w8(pb, MultitrackTypeOneTrack | AudioPacketTypeSequenceStart); |
| 839 | } else { |
| 840 | avio_w8(pb, FLV_CODECID_EX_HEADER | AudioPacketTypeSequenceStart); |
| 841 | } |
| 842 | |
| 843 | write_codec_fourcc(pb, par->codec_id); |
| 844 | |
| 845 | if (track_idx) |
| 846 | avio_w8(pb, track_idx); |
| 847 | |
| 848 | if (par->codec_id == AV_CODEC_ID_AAC) { |
| 849 | flv_write_aac_header(s, par); |
| 850 | } else if (par->codec_id == AV_CODEC_ID_OPUS || par->codec_id == AV_CODEC_ID_FLAC) { |
| 851 | av_assert0(par->extradata_size); |
| 852 | avio_write(pb, par->extradata, par->extradata_size); |
| 853 | } |
| 854 | } else if (par->codec_id == AV_CODEC_ID_AAC) { |
| 855 | avio_w8(pb, get_audio_flags(s, par)); |
| 856 | avio_w8(pb, 0); // AAC sequence header |
| 857 | |
| 858 | flv_write_aac_header(s, par); |
| 859 | } |
| 860 | } else { |
| 861 | // If video stream has track_idx > 0 we need to send H.264 as extended video packet |
| 862 | extended_flv = (par->codec_id == AV_CODEC_ID_H264 && track_idx) || |
no test coverage detected