| 1206 | } |
| 1207 | |
| 1208 | static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) |
| 1209 | { |
| 1210 | AVIOContext *pb = s->pb; |
| 1211 | AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; |
| 1212 | FLVContext *flv = s->priv_data; |
| 1213 | unsigned ts; |
| 1214 | int size = pkt->size; |
| 1215 | uint8_t *data = NULL; |
| 1216 | uint8_t frametype = pkt->flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER; |
| 1217 | int flags = -1, flags_size, ret = 0; |
| 1218 | int64_t cur_offset = avio_tell(pb); |
| 1219 | int track_idx = flv->track_idx_map[pkt->stream_index]; |
| 1220 | |
| 1221 | int extended_audio = (par->codec_id == AV_CODEC_ID_AAC && track_idx) |
| 1222 | || (par->codec_id == AV_CODEC_ID_MP3 && track_idx) |
| 1223 | || par->codec_id == AV_CODEC_ID_OPUS |
| 1224 | || par->codec_id == AV_CODEC_ID_FLAC |
| 1225 | || par->codec_id == AV_CODEC_ID_AC3 |
| 1226 | || par->codec_id == AV_CODEC_ID_EAC3; |
| 1227 | |
| 1228 | if (extended_audio) |
| 1229 | flags_size = 5; |
| 1230 | else if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A || |
| 1231 | par->codec_id == AV_CODEC_ID_VP6 || par->codec_id == AV_CODEC_ID_AAC) |
| 1232 | flags_size = 2; |
| 1233 | else if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4 || |
| 1234 | par->codec_id == AV_CODEC_ID_HEVC || par->codec_id == AV_CODEC_ID_AV1 || |
| 1235 | par->codec_id == AV_CODEC_ID_VP9 || par->codec_id == AV_CODEC_ID_VVC) |
| 1236 | flags_size = 5; |
| 1237 | else |
| 1238 | flags_size = 1; |
| 1239 | |
| 1240 | if ((par->codec_type == AVMEDIA_TYPE_VIDEO || par->codec_type == AVMEDIA_TYPE_AUDIO) && track_idx) |
| 1241 | flags_size += 2; // additional header bytes for multi-track flv |
| 1242 | |
| 1243 | if ((par->codec_id == AV_CODEC_ID_HEVC || par->codec_id == AV_CODEC_ID_VVC || |
| 1244 | (par->codec_id == AV_CODEC_ID_H264 && track_idx)) |
| 1245 | && pkt->pts != pkt->dts) |
| 1246 | flags_size += 3; |
| 1247 | |
| 1248 | if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264 |
| 1249 | || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC |
| 1250 | || par->codec_id == AV_CODEC_ID_VVC |
| 1251 | || par->codec_id == AV_CODEC_ID_AV1 || par->codec_id == AV_CODEC_ID_VP9 |
| 1252 | || par->codec_id == AV_CODEC_ID_OPUS || par->codec_id == AV_CODEC_ID_FLAC) { |
| 1253 | size_t side_size; |
| 1254 | uint8_t *side = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size); |
| 1255 | if (side && side_size > 0 && (side_size != par->extradata_size || memcmp(side, par->extradata, side_size))) { |
| 1256 | ret = ff_alloc_extradata(par, side_size); |
| 1257 | if (ret < 0) |
| 1258 | return ret; |
| 1259 | memcpy(par->extradata, side, side_size); |
| 1260 | flv_write_codec_header(s, par, pkt->dts, pkt->stream_index); |
| 1261 | } |
| 1262 | flv_write_metadata_packet(s, par, pkt->dts, pkt->stream_index); |
| 1263 | } |
| 1264 | |
| 1265 | if (flv->delay == AV_NOPTS_VALUE) |
nothing calls this directly
no test coverage detected