Change frame rate or audio mapping details
| 819 | |
| 820 | // Change frame rate or audio mapping details |
| 821 | void FrameMapper::ChangeMapping(Fraction target_fps, PulldownType target_pulldown, int target_sample_rate, int target_channels, ChannelLayout target_channel_layout) |
| 822 | { |
| 823 | // Prevent concurrent GetFrame()/Init()/Close() calls from using or freeing |
| 824 | // the resampler while this mapping update is in progress. |
| 825 | const std::lock_guard<std::recursive_mutex> lock(getFrameMutex); |
| 826 | |
| 827 | ZmqLogger::Instance()->AppendDebugMethod( |
| 828 | "FrameMapper::ChangeMapping", |
| 829 | "target_fps.num", target_fps.num, |
| 830 | "target_fps.den", target_fps.den, |
| 831 | "target_pulldown", target_pulldown, |
| 832 | "target_sample_rate", target_sample_rate, |
| 833 | "target_channels", target_channels, |
| 834 | "target_channel_layout", target_channel_layout); |
| 835 | |
| 836 | // Mark as dirty |
| 837 | is_dirty = true; |
| 838 | |
| 839 | // Update mapping details |
| 840 | target.num = target_fps.num; |
| 841 | target.den = target_fps.den; |
| 842 | info.fps.num = target_fps.num; |
| 843 | info.fps.den = target_fps.den; |
| 844 | info.video_timebase.num = target_fps.den; |
| 845 | info.video_timebase.den = target_fps.num; |
| 846 | info.video_length = round(info.duration * info.fps.ToDouble()); |
| 847 | pulldown = target_pulldown; |
| 848 | info.sample_rate = target_sample_rate; |
| 849 | info.channels = target_channels; |
| 850 | info.channel_layout = target_channel_layout; |
| 851 | |
| 852 | // Enable/Disable audio (based on settings) |
| 853 | info.has_audio = info.sample_rate > 0 && info.channels > 0; |
| 854 | |
| 855 | // Clear cache |
| 856 | final_cache.Clear(); |
| 857 | |
| 858 | // Adjust cache size based on size of frame and audio |
| 859 | const int reset_cache_frames = std::max(Settings::Instance()->CACHE_MIN_FRAMES, OPEN_MP_NUM_PROCESSORS * 4); |
| 860 | final_cache.SetMaxBytesFromInfo(reset_cache_frames, info.width, info.height, info.sample_rate, info.channels); |
| 861 | |
| 862 | // Deallocate resample buffer |
| 863 | if (avr) { |
| 864 | SWR_CLOSE(avr); |
| 865 | SWR_FREE(&avr); |
| 866 | avr = NULL; |
| 867 | } |
| 868 | |
| 869 | // Reset direction/resampler continuity after a mapping change. |
| 870 | previous_frame = 0; |
| 871 | const std::lock_guard<std::recursive_mutex> direction_lock(directionMutex); |
| 872 | have_hint = false; |
| 873 | last_dir_initialized = false; |
| 874 | last_is_increasing = true; |
| 875 | } |
| 876 | |
| 877 | // Resample audio and map channels (if needed) |
| 878 | void FrameMapper::ResampleMappedAudio(std::shared_ptr<Frame> frame, int64_t original_frame_number) |
no test coverage detected