Bring back to working
parent
bd9c15713d
commit
1bfa9366e6
|
@ -36,58 +36,10 @@ module Rex
|
|||
end
|
||||
|
||||
# Starts recording video from video source of index +cam+
|
||||
def mic_start(mic_index=0, start_delay)
|
||||
def mic_start
|
||||
request = Packet.create_request('audio_interface_start')
|
||||
request.add_tlv(TLV_TYPE_AUDIO_INTERFACE_NAME, mic_index)
|
||||
request.add_tlv(TLV_TYPE_AUDIO_INTERFACE_NAME, 0)
|
||||
response = client.send_request(request)
|
||||
begin
|
||||
client.mic.mic_start(index)
|
||||
mic_started = true
|
||||
::Timeout.timeout(duration) do
|
||||
::File.open(stream_path, 'wb') do |outfd|
|
||||
numchannels = 1
|
||||
sampleratehz = 11025
|
||||
bitspersample = 16
|
||||
datasize = 2000000000
|
||||
subchunk1size = 16
|
||||
chunksize = 4 + (8 + subchunk1size) + (8 + datasize)
|
||||
byterate = sampleratehz * numchannels * bitspersample / 8
|
||||
blockalign = numchannels * bitspersample / 8
|
||||
|
||||
BinData::Int32be.new(0x52494646).write(outfd) # ChunkID: "RIFF"
|
||||
BinData::Int32le.new(chunksize).write(outfd) # ChunkSize
|
||||
BinData::Int32be.new(0x57415645).write(outfd) # Format: "WAVE"
|
||||
BinData::Int32be.new(0x666d7420).write(outfd) # SubChunk1ID: "fmt "
|
||||
BinData::Int32le.new(16).write(outfd) # SubChunk1Size
|
||||
BinData::Int16le.new(1).write(outfd) # AudioFormat
|
||||
BinData::Int16le.new(numchannels).write(outfd) # NumChannels
|
||||
BinData::Int32le.new(sampleratehz).write(outfd) # SampleRate
|
||||
BinData::Int32le.new(byterate).write(outfd) # ByteRate
|
||||
BinData::Int16le.new(blockalign).write(outfd) # BlockAlign
|
||||
BinData::Int16le.new(bitspersample).write(outfd) # BitsPerSample
|
||||
BinData::Int32be.new(0x64617461).write(outfd) # SubChunk2ID: "data"
|
||||
BinData::Int32le.new(datasize).write(outfd) # SubChunk2Size
|
||||
end
|
||||
stream_index = 0
|
||||
while client do
|
||||
if stream_index == start_delay
|
||||
cmd_listen(stream_path)
|
||||
end
|
||||
data = client.mic.mic_get_frame(quality)
|
||||
if data
|
||||
::File.open(stream_path, 'a') do |f|
|
||||
f.write(data)
|
||||
end
|
||||
data = nil
|
||||
end
|
||||
stream_index += 1
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
rescue ::Timeout::Error
|
||||
ensure
|
||||
client.mic.mic_stop if mic_started
|
||||
end
|
||||
end
|
||||
|
||||
def mic_get_frame(quality)
|
||||
|
|
|
@ -49,7 +49,7 @@ module Rex
|
|||
end
|
||||
end
|
||||
|
||||
def cmd_mic_start(mic_index=0, start_delay=4096)
|
||||
def cmd_mic_start(start_delay=4096)
|
||||
print_status("Streaming mic audio channel...")
|
||||
|
||||
if client.mic.mic_list.length == 0
|
||||
|
@ -65,16 +65,62 @@ module Rex
|
|||
print_status("Audio File: #{stream_path}")
|
||||
print_status("Streaming...")
|
||||
|
||||
client.mic_start(mic_index, start_delay)
|
||||
end
|
||||
begin
|
||||
client.mic.mic_start
|
||||
mic_started = true
|
||||
::Timeout.timeout(duration) do
|
||||
::File.open(stream_path, 'wb') do |outfd|
|
||||
numchannels = 1
|
||||
sampleratehz = 11025
|
||||
bitspersample = 16
|
||||
datasize = 2000000000
|
||||
subchunk1size = 16
|
||||
chunksize = 4 + (8 + subchunk1size) + (8 + datasize)
|
||||
byterate = sampleratehz * numchannels * bitspersample / 8
|
||||
blockalign = numchannels * bitspersample / 8
|
||||
|
||||
def cmd_mic_stop
|
||||
client.mic.mic_stop
|
||||
BinData::Int32be.new(0x52494646).write(outfd) # ChunkID: "RIFF"
|
||||
BinData::Int32le.new(chunksize).write(outfd) # ChunkSize
|
||||
BinData::Int32be.new(0x57415645).write(outfd) # Format: "WAVE"
|
||||
BinData::Int32be.new(0x666d7420).write(outfd) # SubChunk1ID: "fmt "
|
||||
BinData::Int32le.new(16).write(outfd) # SubChunk1Size
|
||||
BinData::Int16le.new(1).write(outfd) # AudioFormat
|
||||
BinData::Int16le.new(numchannels).write(outfd) # NumChannels
|
||||
BinData::Int32le.new(sampleratehz).write(outfd) # SampleRate
|
||||
BinData::Int32le.new(byterate).write(outfd) # ByteRate
|
||||
BinData::Int16le.new(blockalign).write(outfd) # BlockAlign
|
||||
BinData::Int16le.new(bitspersample).write(outfd) # BitsPerSample
|
||||
BinData::Int32be.new(0x64617461).write(outfd) # SubChunk2ID: "data"
|
||||
BinData::Int32le.new(datasize).write(outfd) # SubChunk2Size
|
||||
end
|
||||
stream_index = 0
|
||||
while client do
|
||||
if stream_index == start_delay
|
||||
cmd_listen(stream_path)
|
||||
end
|
||||
data = client.mic.mic_get_frame(quality)
|
||||
if data
|
||||
::File.open(stream_path, 'a') do |f|
|
||||
f.write(data)
|
||||
end
|
||||
data = nil
|
||||
end
|
||||
stream_index += 1
|
||||
end
|
||||
end
|
||||
rescue ::Timeout::Error
|
||||
ensure
|
||||
client.mic.mic_stop if mic_started
|
||||
end
|
||||
end
|
||||
|
||||
def cmd_listen(stream_path)
|
||||
Rex::Compat.open_webrtc_browser("file://#{::File.absolute_path(stream_path)}")
|
||||
end
|
||||
|
||||
def cmd_mic_stop
|
||||
client.mic.mic_stop
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue