Process an audio packet
| 2076 | |
| 2077 | // Process an audio packet |
| 2078 | void FFmpegReader::ProcessAudioPacket(int64_t requested_frame) { |
| 2079 | AudioLocation location; |
| 2080 | // Calculate location of current audio packet |
| 2081 | if (packet && packet->pts != AV_NOPTS_VALUE) { |
| 2082 | // Determine related video frame and starting sample # from audio PTS |
| 2083 | location = GetAudioPTSLocation(packet->pts); |
| 2084 | |
| 2085 | // Track 1st audio packet after a successful seek |
| 2086 | if (!seek_audio_frame_found && is_seeking) |
| 2087 | seek_audio_frame_found = location.frame; |
| 2088 | } |
| 2089 | |
| 2090 | // Create or get the existing frame object. Requested frame needs to be created |
| 2091 | // in working_cache at least once. Seek can clear the working_cache, so we must |
| 2092 | // add the requested frame back to the working_cache here. If it already exists, |
| 2093 | // it will be moved to the top of the working_cache. |
| 2094 | working_cache.Add(CreateFrame(requested_frame)); |
| 2095 | |
| 2096 | // Debug output |
| 2097 | ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (Before)", |
| 2098 | "requested_frame", requested_frame, |
| 2099 | "target_frame", location.frame, |
| 2100 | "starting_sample", location.sample_start); |
| 2101 | |
| 2102 | // Init an AVFrame to hold the decoded audio samples |
| 2103 | int frame_finished = 0; |
| 2104 | AVFrame *audio_frame = AV_ALLOCATE_FRAME(); |
| 2105 | AV_RESET_FRAME(audio_frame); |
| 2106 | |
| 2107 | int packet_samples = 0; |
| 2108 | int data_size = 0; |
| 2109 | |
| 2110 | #if IS_FFMPEG_3_2 |
| 2111 | int send_packet_err = avcodec_send_packet(aCodecCtx, packet); |
| 2112 | if (send_packet_err < 0 && send_packet_err != AVERROR_EOF) { |
| 2113 | ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (Packet not sent)"); |
| 2114 | } |
| 2115 | else { |
| 2116 | int receive_frame_err = avcodec_receive_frame(aCodecCtx, audio_frame); |
| 2117 | if (receive_frame_err >= 0) { |
| 2118 | frame_finished = 1; |
| 2119 | } |
| 2120 | if (receive_frame_err == AVERROR_EOF) { |
| 2121 | ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (EOF detected from decoder)"); |
| 2122 | packet_status.audio_eof = true; |
| 2123 | } |
| 2124 | if (receive_frame_err == AVERROR(EINVAL) || receive_frame_err == AVERROR_EOF) { |
| 2125 | ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (invalid frame received or EOF from decoder)"); |
| 2126 | avcodec_flush_buffers(aCodecCtx); |
| 2127 | } |
| 2128 | if (receive_frame_err != 0) { |
| 2129 | ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (frame not ready yet from decoder)"); |
| 2130 | } |
| 2131 | } |
| 2132 | #else |
| 2133 | int used = avcodec_decode_audio4(aCodecCtx, audio_frame, &frame_finished, packet); |
| 2134 | #endif |
| 2135 |
nothing calls this directly
no test coverage detected