| 816 | } |
| 817 | |
| 818 | static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) |
| 819 | { |
| 820 | int ret = 0; |
| 821 | |
| 822 | /* apply the output bitstream filters, if any */ |
| 823 | if (ost->nb_bitstream_filters) { |
| 824 | int idx; |
| 825 | |
| 826 | ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt); |
| 827 | if (ret < 0) |
| 828 | goto finish; |
| 829 | |
| 830 | idx = 1; |
| 831 | while (idx) { |
| 832 | /* get a packet from the previous filter up the chain */ |
| 833 | ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt); |
| 834 | if (ret == AVERROR(EAGAIN)) { |
| 835 | ret = 0; |
| 836 | idx--; |
| 837 | continue; |
| 838 | } else if (ret < 0) |
| 839 | goto finish; |
| 840 | /* HACK! - aac_adtstoasc updates extradata after filtering the first frame when |
| 841 | * the api states this shouldn't happen after init(). Propagate it here to the |
| 842 | * muxer and to the next filters in the chain to workaround this. |
| 843 | * TODO/FIXME - Make aac_adtstoasc use new packet side data instead of changing |
| 844 | * par_out->extradata and adapt muxers accordingly to get rid of this. */ |
| 845 | if (!(ost->bsf_extradata_updated[idx - 1] & 1)) { |
| 846 | ret = avcodec_parameters_copy(ost->st->codecpar, ost->bsf_ctx[idx - 1]->par_out); |
| 847 | if (ret < 0) |
| 848 | goto finish; |
| 849 | ost->bsf_extradata_updated[idx - 1] |= 1; |
| 850 | } |
| 851 | |
| 852 | /* send it to the next filter down the chain or to the muxer */ |
| 853 | if (idx < ost->nb_bitstream_filters) { |
| 854 | /* HACK/FIXME! - See above */ |
| 855 | if (!(ost->bsf_extradata_updated[idx] & 2)) { |
| 856 | ret = avcodec_parameters_copy(ost->bsf_ctx[idx]->par_out, ost->bsf_ctx[idx - 1]->par_out); |
| 857 | if (ret < 0) |
| 858 | goto finish; |
| 859 | ost->bsf_extradata_updated[idx] |= 2; |
| 860 | } |
| 861 | ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt); |
| 862 | if (ret < 0) |
| 863 | goto finish; |
| 864 | idx++; |
| 865 | } else |
| 866 | write_packet(of, pkt, ost, 0); |
| 867 | } |
| 868 | } else |
| 869 | write_packet(of, pkt, ost, 0); |
| 870 | |
| 871 | finish: |
| 872 | if (ret < 0 && ret != AVERROR_EOF) { |
| 873 | av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output " |
| 874 | "packet for stream #%d:%d.\n", ost->file_index, ost->index); |
| 875 | if(exit_on_error) |
no test coverage detected