diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index 45a9b86f..75fd918e 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -11,7 +11,14 @@ def item # use params to get query string or parsed route parameters # get the path for the file matching the request - @file_path = Cache::calculate_target_path(params) + file_name = Cache::cached_spectrogram_file(params) + #file_name = Cache::cached_audio_file(params) + #file_name = Cache::original_audio_file({ :id => '21EC2020-3AEA-1069-A2DD-08002B30309D', :date => '20121026', :time => '132600', :format => 'wav'}) + + #@file_path = Cache::possible_paths(file_name) + #@file_path = Cache::existing_paths(Cache::cached_spectrogram_storage_paths,file_name) + #@file_path = QubarSite::Application.config.media_file_config.cached_spectrogram_paths + @file_path = Cache::possible_paths(Cache::cached_spectrogram_storage_paths,file_name) # see if the requested file exists diff --git a/lib/modules/cache.rb b/lib/modules/cache.rb index 9bd036f9..abc8d36e 100644 --- a/lib/modules/cache.rb +++ b/lib/modules/cache.rb @@ -1,17 +1,119 @@ +require 'String' + +# Determines file names for cached and original files. module Cache + @parameter_file_name_separator = '_' + public - # calculate the target file name and path based on the modification parameters - def self.calculate_target_path(modify_parameters = {}) - #Mime::Type.lookup_by_extension( - #QubarSite::Application.config.media_file_config + #original audio + + # get the file name for an original audio file + def self.original_audio_file(modify_parameters = {}) + file_name = self.build_parameters [ :id, :date, :time, :format ], modify_parameters + file_name + end + + # get all the storage paths for original audio + def self.original_audio_storage_paths() + storage_paths = QubarSite::Application.config.media_file_config.original_audio_paths + storage_paths + end + + # cached audio + + # get the file name for a cached audio file + def self.cached_audio_file(modify_parameters = {}) + file_name = self.build_parameters [ :id, :start_offset, :end_offset, :channel, :sample_rate, :format ], modify_parameters + file_name + end + + # get all the storage paths for cached audio + def self.cached_audio_storage_paths() + storage_paths = QubarSite::Application.config.media_file_config.cached_audio_paths + storage_paths + end + + def self. cached_audio_defaults() + cache_defaults = QubarSite::Application.config.media_file_config.cached_audio_defaults + cache_defaults + end + + def self. cached_spectrogram_defaults() + cache_defaults = QubarSite::Application.config.media_file_config.cached_spectrogram_defaults + cache_defaults end - # check to see if a target file exists - def self.exists(source, modify_parameters = {}) - File.exists? calculate_target_path(source, modify_parameters) + # cached spectrograms + + # get the file name for a cached spectrogram + def self.cached_spectrogram_file(modify_parameters = {}) + file_name = self.build_parameters [ :id, :start_offset, :end_offset, :channel, :sample_rate, :window, :colour, :format ], modify_parameters + file_name + end + + # get all the storage paths for cached spectrograms + def self.cached_spectrogram_storage_paths() + storage_paths = QubarSite::Application.config.media_file_config.cached_spectrogram_paths + storage_paths + end + + # get all possible full paths for a file + def self.possible_paths(storage_paths, file_name) + possible_paths = storage_paths.collect { |path| File.join(path,file_name) } + possible_paths + end + + # get the full paths for all existing files that match a file name + def self.existing_paths(storage_paths, file_name) + existing_paths = possible_paths(storage_paths, file_name).find_all {|file| File.exists? file } + existing_paths end private + + def self.build_parameters(parameter_names = {}, modify_parameters = {}) + file_name = '' + + parameter_names.each do |param| + if param == :id + file_name += get_parameter(:id, modify_parameters, false) + elsif param == :format + file_name += '.'+get_parameter(:format, modify_parameters, false) + else + file_name += get_parameter(param, modify_parameters) + end + end + + file_name + end + + def self.get_parameter(parameter, modify_parameters, include_separator = true) + # need to cater for the situation where modify_parameters contains strings (we want symbols) + modify_parameters.keys.each do |key| + modify_parameters[(key.to_sym rescue key) || key] = modify_parameters.delete(key) + end + + # need to cater for the situation where parameter is a string (we want a symbol) + parameter = parameter.to_s.to_sym + + raise ArgumentError, "Parameters must include #{parameter}." unless modify_parameters.include? parameter + result_name = '' + + if modify_parameters.include? parameter + result_name = modify_parameters[parameter] + + if parameter == :format + result_name = result_name.trim '.', '' + end + + if include_separator + result_name = @parameter_file_name_separator+result_name + end + end + + result_name + end + end \ No newline at end of file diff --git a/lib/modules/string.rb b/lib/modules/string.rb index 6e3d071b..2734c553 100644 --- a/lib/modules/string.rb +++ b/lib/modules/string.rb @@ -1,5 +1,5 @@ class String - def trim(replace_chars, substitute_chars) - "#{self}".gsub(/^[#{substitute_chars}]+|[#{substitute_chars}]+$/, replace_chars) + def trim(chars_to_replace, char_to_insert) + "#{self}".gsub(/^[#{chars_to_replace}]+|[#{chars_to_replace}]+$/, char_to_insert) end end \ No newline at end of file diff --git a/public/tests/TorresianCrow.wav b/public/tests/TorresianCrow.wav new file mode 100644 index 00000000..c916b6c3 Binary files /dev/null and b/public/tests/TorresianCrow.wav differ diff --git a/vendor/bin/ffmpeg/windows/ffprobe-help.txt b/vendor/bin/ffmpeg/windows/ffprobe-help.txt new file mode 100644 index 00000000..0a7b2232 --- /dev/null +++ b/vendor/bin/ffmpeg/windows/ffprobe-help.txt @@ -0,0 +1,481 @@ +Simple multimedia streams analyzer +usage: ffprobe [OPTIONS] [INPUT_FILE] + +Main options: +-L show license +-h topic show help +-? topic show help +-help topic show help +--help topic show help +-version show version +-formats show available formats +-codecs show available codecs +-decoders show available decoders +-encoders show available encoders +-bsfs show available bit stream filters +-protocols show available protocols +-filters show available filters +-pix_fmts show available pixel formats +-layouts show standard channel layouts +-sample_fmts show available audio sample formats +-loglevel loglevel set libav* logging level +-v loglevel set libav* logging level +-debug flags set debug flags +-fdebug flags set debug flags +-report generate a report +-max_alloc bytes set maximum size of a single allocated block +-cpuflags flags force specific cpu flags +-f format force format +-unit show unit of the displayed values +-prefix use SI prefixes for the displayed values +-byte_binary_prefix use binary prefixes for byte units +-sexagesimal use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units +-pretty prettify the format of displayed values, make it more human readable +-print_format format set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml) +-of format alias for -print_format +-select_streams stream_specifier select the specified streams +-show_data show packets data +-show_error show probing error +-show_format show format/container info +-show_frames show frames info +-show_format_entry entry show a particular entry from the format/container info +-show_packets show packets info +-show_streams show streams info +-count_frames count the number of frames per stream +-count_packets count the number of packets per stream +-show_program_version show ffprobe version +-show_library_versions show library versions +-show_versions show program and library versions +-show_private_data show private data +-private same as show_private_data +-bitexact force bitexact output +-default generic catch all option +-i input_file read specified file + + +AVFormatContext AVOptions: +-avioflags ED.... + direct ED.... reduce buffering +-probesize .D.... set probing size +-fflags ED.... + ignidx .D.... ignore index + genpts .D.... generate pts + nofillin .D.... do not fill in missing values that can be exactly calculated + noparse .D.... disable AVParsers, this needs nofillin too + igndts .D.... ignore dts + discardcorrupt .D.... discard corrupted frames + sortdts .D.... try to interleave outputted packets by dts + keepside .D.... dont merge side data + nobuffer .D.... reduce the latency introduced by optional buffering +-analyzeduration .D.... how many microseconds are analyzed to estimate duration +-cryptokey .D.... decryption key +-indexmem .D.... max memory used for timestamp index (per stream) +-rtbufsize .D.... max memory used for buffering real-time frames +-fdebug ED.... print specific debug info + ts ED.... +-max_delay ED.... maximum muxing or demuxing delay in microseconds +-fpsprobesize .D.... number of frames used to probe fps +-f_err_detect .D.... set error detection flags (deprecated; use err_detect, save via avconv) + crccheck .D.... verify embedded CRCs + bitstream .D.... detect bitstream specification deviations + buffer .D.... detect improper bitstream length + explode .D.... abort decoding on minor error detection + careful .D.... consider things that violate the spec and have not been seen in the wild as errors + compliant .D.... consider all spec non compliancies as errors + aggressive .D.... consider things that a sane encoder shouldnt do as an error +-err_detect .D.... set error detection flags + crccheck .D.... verify embedded CRCs + bitstream .D.... detect bitstream specification deviations + buffer .D.... detect improper bitstream length + explode .D.... abort decoding on minor error detection + careful .D.... consider things that violate the spec and have not been seen in the wild as errors + compliant .D.... consider all spec non compliancies as errors + aggressive .D.... consider things that a sane encoder shouldnt do as an error +-use_wallclock_as_timestamps .D.... use wallclock as timestamps + +AVIOContext AVOptions: + +URLContext AVOptions: + +crypto AVOptions: +-key .D.... AES decryption key +-iv .D.... AES decryption initialization vector + +file AVOptions: + +http AVOptions: +-seekable .D.... Control seekability of connection +-headers ED.... custom HTTP headers, can override built in default headers +-user-agent .D.... override User-Agent header +-multiple_requests ED.... use persistent connections +-post_data ED.... custom HTTP post data +-timeout ED.... timeout of socket i/o operations + +tcp AVOptions: +-listen ED.... listen on port instead of connecting +-timeout ED.... timeout of socket i/o operations +-listen_timeout ED.... connection awaiting timeout + +udp AVOptions: +-buffer_size ED.... Socket buffer size in bytes +-localport ED.... Set local port to bind to +-localaddr ED.... Choose local IP address +-pkt_size ED.... Set size of UDP packets +-reuse ED.... Explicitly allow or disallow reusing UDP sockets +-connect ED.... Should connect() be called on socket +-fifo_size .D.... Set the UDP receiving circular buffer size, expressed as a number of packets with size of 188 bytes +-overrun_nonfatal .D.... Survive in case of UDP receiving circular buffer overrun +-timeout .D.... In read mode: if no data arrived in more than this time interval, raise error + +librtmp protocol AVOptions: +-rtmp_app ED.... Name of application to connect to on the RTMP server +-rtmp_playpath ED.... Stream identifier to play or to publish + +librtmpe protocol AVOptions: +-rtmp_app ED.... Name of application to connect to on the RTMP server +-rtmp_playpath ED.... Stream identifier to play or to publish + +librtmps protocol AVOptions: +-rtmp_app ED.... Name of application to connect to on the RTMP server +-rtmp_playpath ED.... Stream identifier to play or to publish + +librtmpt protocol AVOptions: +-rtmp_app ED.... Name of application to connect to on the RTMP server +-rtmp_playpath ED.... Stream identifier to play or to publish + +librtmpte protocol AVOptions: +-rtmp_app ED.... Name of application to connect to on the RTMP server +-rtmp_playpath ED.... Stream identifier to play or to publish + +Artworx Data Format demuxer AVOptions: +-linespeed .D.... set simulated line speed (bytes per second) +-video_size .D.... set video size, such as 640x480 or hd720. +-framerate .D.... set framerate (frames per second) + +asf demuxer AVOptions: +-no_resync_search .D.... Don't try to resynchronize by looking for a certain optional start code + +avi AVOptions: +-use_odml .D.... use odml index + +Binary text demuxer AVOptions: +-linespeed .D.... set simulated line speed (bytes per second) +-video_size .D.... set video size, such as 640x480 or hd720. +-framerate .D.... set framerate (frames per second) + +cavsvideo demuxer AVOptions: +-framerate .D.... + +CDXL demuxer AVOptions: +-sample_rate .D.... +-framerate .D.... + +dirac demuxer AVOptions: +-framerate .D.... + +dnxhd demuxer AVOptions: +-framerate .D.... + +flvdec AVOptions: +-flv_metadata .D.V.. Allocate streams according the onMetaData array + +g729 demuxer AVOptions: +-bit_rate .D.... + +gsm demuxer AVOptions: +-sample_rate .D.... + +h261 demuxer AVOptions: +-framerate .D.... + +h263 demuxer AVOptions: +-framerate .D.... + +h264 demuxer AVOptions: +-framerate .D.... + +iCE Draw File demuxer AVOptions: +-linespeed .D.... set simulated line speed (bytes per second) +-video_size .D.... set video size, such as 640x480 or hd720. +-framerate .D.... set framerate (frames per second) + +image2 demuxer AVOptions: +-framerate .D.... set the video framerate +-loop .D.... force loop over input file sequence +-pattern_type .D.... set pattern type + glob_sequence .D.... glob/sequence pattern type + glob .D.... glob pattern type + sequence .D.... glob pattern type +-pixel_format .D.... set video pixel format +-start_number .D.... set first number in the sequence +-start_number_range .D.... set range for looking at the first sequence number +-video_size .D.... set video size + +image2pipe demuxer AVOptions: +-framerate .D.... set the video framerate +-loop .D.... force loop over input file sequence +-pattern_type .D.... set pattern type + glob_sequence .D.... glob/sequence pattern type + glob .D.... glob pattern type + sequence .D.... glob pattern type +-pixel_format .D.... set video pixel format +-start_number .D.... set first number in the sequence +-start_number_range .D.... set range for looking at the first sequence number +-video_size .D.... set video size + +ingenient demuxer AVOptions: +-framerate .D.... + +m4v demuxer AVOptions: +-framerate .D.... + +mjpeg demuxer AVOptions: +-framerate .D.... + +mov,mp4,m4a,3gp,3g2,mj2 AVOptions: +-use_absolute_path .D.V.. allow using absolute path when opening alias, this is a possible security issue +-ignore_editlist .D.V.. + +mpegtsraw demuxer AVOptions: +-compute_pcr .D.... Compute exact PCR for each transport stream packet. + +mpegvideo demuxer AVOptions: +-framerate .D.... + +alaw demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +mulaw demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +f64be demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +f64le demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +f32be demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +f32le demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +s32be demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +s32le demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +s24be demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +s24le demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +s16be demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +s16le demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +s8 demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +u32be demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +u32le demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +u24be demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +u24le demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +u16be demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +u16le demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +u8 demuxer AVOptions: +-sample_rate .D.... +-channels .D.... + +rawvideo demuxer AVOptions: +-video_size .D.... A string describing frame size, such as 640x480 or hd720. +-pixel_format .D.... +-framerate .D.... + +RTP demuxer AVOptions: +-rtp_flags .D.... RTP flags + filter_src .D.... Only receive packets from the negotiated peer IP + listen .D.... Wait for incoming connections +-reorder_queue_size .D.... Number of packets to buffer for handling of reordered packets + +RTSP demuxer AVOptions: +-initial_pause .D.... Don't start playing the stream immediately +-rtsp_transport ED.... RTSP transport protocols + udp ED.... UDP + tcp ED.... TCP + udp_multicast .D.... UDP multicast + http .D.... HTTP tunneling +-rtsp_flags .D.... RTSP flags + filter_src .D.... Only receive packets from the negotiated peer IP + listen .D.... Wait for incoming connections +-allowed_media_types .D.... Media types to accept from the server + video .D.... Video + audio .D.... Audio + data .D.... Data +-min_port ED.... Minimum local UDP port +-max_port ED.... Maximum local UDP port +-timeout .D.... Maximum timeout (in seconds) to wait for incoming connections. -1 is infinite. Implies flag listen +-reorder_queue_size .D.... Number of packets to buffer for handling of reordered packets + +sbg_demuxer AVOptions: +-sample_rate .D.... +-frame_size .D.... +-max_file_size .D.... + +SDP demuxer AVOptions: +-sdp_flags .D.... SDP flags + filter_src .D.... Only receive packets from the negotiated peer IP + listen .D.... Wait for incoming connections +-allowed_media_types .D.... Media types to accept from the server + video .D.... Video + audio .D.... Audio + data .D.... Data +-reorder_queue_size .D.... Number of packets to buffer for handling of reordered packets + +TTY demuxer AVOptions: +-chars_per_frame .D.... +-video_size .D.... A string describing frame size, such as 640x480 or hd720. +-framerate .D.... + +vc1 demuxer AVOptions: +-framerate .D.... + +WAV demuxer AVOptions: +-ignore_length .D.... Ignore length + +eXtended BINary text (XBIN) demuxer AVOptions: +-linespeed .D.... set simulated line speed (bytes per second) +-video_size .D.... set video size, such as 640x480 or hd720. +-framerate .D.... set framerate (frames per second) + +DirectShow indev AVOptions: +-video_size .D.... set video size given a string such as 640x480 or hd720. +-pixel_format .D.... set video pixel format +-framerate .D.... set video frame rate +-sample_rate .D.... set audio sample rate +-sample_size .D.... set audio sample size +-channels .D.... set number of audio channels, such as 1 or 2 +-list_devices .D.... list available devices + true .D.... + false .D.... +-list_options .D.... list available options for specified device + true .D.... + false .D.... +-video_device_number .D.... set video device number for devices with same name (starts at 0) +-audio_device_number .D.... set audio device number for devices with same name (starts at 0) +-audio_buffer_size .D.... set audio device buffer latency size in milliseconds (default is the device's default) + +lavfi indev AVOptions: +-graph .D.... set libavfilter graph +-dumpgraph .D.... dump graph to stderr + +VFW indev AVOptions: +-video_size .D.... A string describing frame size, such as 640x480 or hd720. +-framerate .D.... + +f4v muxer AVOptions: + +GIF muxer AVOptions: + +image2 muxer AVOptions: + +ipod muxer AVOptions: + +ismv muxer AVOptions: + +LATM/LOAS muxer AVOptions: + +mov muxer AVOptions: + +MP3 muxer AVOptions: + +mp4 muxer AVOptions: + +mpeg muxer AVOptions: + +vcd muxer AVOptions: + +dvd muxer AVOptions: + +svcd muxer AVOptions: + +vob muxer AVOptions: + +MPEGTS muxer AVOptions: + +Ogg muxer AVOptions: + +psp muxer AVOptions: + +RTP muxer AVOptions: + +RTSP muxer AVOptions: +-initial_pause .D.... Don't start playing the stream immediately +-rtsp_transport ED.... RTSP transport protocols + udp ED.... UDP + tcp ED.... TCP + udp_multicast .D.... UDP multicast + http .D.... HTTP tunneling +-rtsp_flags .D.... RTSP flags + filter_src .D.... Only receive packets from the negotiated peer IP + listen .D.... Wait for incoming connections +-allowed_media_types .D.... Media types to accept from the server + video .D.... Video + audio .D.... Audio + data .D.... Data +-min_port ED.... Minimum local UDP port +-max_port ED.... Maximum local UDP port +-timeout .D.... Maximum timeout (in seconds) to wait for incoming connections. -1 is infinite. Implies flag listen +-reorder_queue_size .D.... Number of packets to buffer for handling of reordered packets + +segment muxer AVOptions: + +stream_segment muxer AVOptions: + +smooth streaming muxer AVOptions: + +spdif AVOptions: + +tg2 muxer AVOptions: + +tgp muxer AVOptions: + +WAV muxer AVOptions: + +sdl outdev AVOptions: +