1 /***************************************************************************** 2 * libavsmash_source.h 3 ***************************************************************************** 4 * Copyright (C) 2012-2015 L-SMASH Works project 5 * 6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com> 7 * 8 * Permission to use, copy, modify, and/or distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 *****************************************************************************/ 20 21 /* This file is available under an ISC license. 22 * However, when distributing its binary file, it will be under LGPL or GPL. */ 23 24 #include "../common/libavsmash.h" 25 #include "../common/libavsmash_video.h" 26 #include "../common/libavsmash_audio.h" 27 28 class LibavSMASHSource : public LSMASHSource 29 { 30 private: 31 void (*free_format_ctx)( AVFormatContext *p ) 32 = []( AVFormatContext *p ){ avformat_close_input( &p ); }; 33 protected: 34 lsmash_file_parameters_t file_param; 35 std::unique_ptr< AVFormatContext, decltype( free_format_ctx ) > format_ctx; LibavSMASHSource()36 LibavSMASHSource() : format_ctx{ nullptr, free_format_ctx } {} 37 ~LibavSMASHSource() = default; 38 LibavSMASHSource( const LibavSMASHSource & ) = delete; 39 LibavSMASHSource & operator= ( const LibavSMASHSource & ) = delete; 40 }; 41 42 class LSMASHVideoSource : public LibavSMASHSource 43 { 44 private: 45 std::unique_ptr< libavsmash_video_decode_handler_t, decltype( &libavsmash_video_free_decode_handler ) > vdhp; 46 std::unique_ptr< libavsmash_video_output_handler_t, decltype( &libavsmash_video_free_output_handler ) > vohp; LSMASHVideoSource()47 LSMASHVideoSource() 48 : LibavSMASHSource{}, 49 vdhp{ libavsmash_video_alloc_decode_handler(), libavsmash_video_free_decode_handler }, 50 vohp{ libavsmash_video_alloc_output_handler(), libavsmash_video_free_output_handler } {} 51 uint32_t open_file 52 ( 53 const char *source, 54 IScriptEnvironment *env 55 ); 56 void get_video_track 57 ( 58 const char *source, 59 uint32_t track_number, 60 IScriptEnvironment *env 61 ); 62 public: 63 LSMASHVideoSource 64 ( 65 const char *source, 66 uint32_t track_number, 67 int threads, 68 int seek_mode, 69 uint32_t forward_seek_threshold, 70 int direct_rendering, 71 int fps_num, 72 int fps_den, 73 int stacked_format, 74 enum AVPixelFormat pixel_format, 75 const char *preferred_decoder_names, 76 IScriptEnvironment *env 77 ); 78 ~LSMASHVideoSource(); 79 PVideoFrame __stdcall GetFrame( int n, IScriptEnvironment *env ); GetParity(int n)80 bool __stdcall GetParity( int n ) { return false; } GetAudio(void * buf,__int64 start,__int64 count,IScriptEnvironment * env)81 void __stdcall GetAudio( void *buf, __int64 start, __int64 count, IScriptEnvironment *env ) {} 82 }; 83 84 class LSMASHAudioSource : public LibavSMASHSource 85 { 86 private: 87 std::unique_ptr< libavsmash_audio_decode_handler_t, decltype( &libavsmash_audio_free_decode_handler ) > adhp; 88 std::unique_ptr< libavsmash_audio_output_handler_t, decltype( &libavsmash_audio_free_output_handler ) > aohp; LSMASHAudioSource()89 LSMASHAudioSource() 90 : LibavSMASHSource{}, 91 adhp{ libavsmash_audio_alloc_decode_handler(), libavsmash_audio_free_decode_handler }, 92 aohp{ libavsmash_audio_alloc_output_handler(), libavsmash_audio_free_output_handler } {} 93 uint32_t open_file 94 ( 95 const char *source, 96 IScriptEnvironment *env 97 ); 98 void get_audio_track 99 ( 100 const char *source, 101 uint32_t track_number, 102 IScriptEnvironment *env 103 ); 104 public: 105 LSMASHAudioSource 106 ( 107 const char *source, 108 uint32_t track_number, 109 bool skip_priming, 110 uint64_t channel_layout, 111 int sample_rate, 112 const char *preferred_decoder_names, 113 IScriptEnvironment *env 114 ); 115 ~LSMASHAudioSource(); GetFrame(int n,IScriptEnvironment * env)116 PVideoFrame __stdcall GetFrame( int n, IScriptEnvironment *env ) { return nullptr; } GetParity(int n)117 bool __stdcall GetParity( int n ) { return false; } 118 void __stdcall GetAudio( void *buf, __int64 start, __int64 wanted_length, IScriptEnvironment *env ); 119 }; 120