From d32eac7394c274a286dff1bb23ae5bb928770c33 Mon Sep 17 00:00:00 2001 From: scruzin Date: Thu, 8 Aug 2019 14:39:55 +0930 Subject: [PATCH 1/4] Moved audio support to OS-specific files. --- revid/audio_linux.go | 51 ++++++++++++++++++++++++++++++++++++++++++++ revid/revid.go | 46 --------------------------------------- 2 files changed, 51 insertions(+), 46 deletions(-) create mode 100644 revid/audio_linux.go diff --git a/revid/audio_linux.go b/revid/audio_linux.go new file mode 100644 index 00000000..3224ce68 --- /dev/null +++ b/revid/audio_linux.go @@ -0,0 +1,51 @@ +package revid + +import ( + "bitbucket.org/ausocean/av/container/mts" + "bitbucket.org/ausocean/av/input/audio" +) + +// startAudioDevice is used to start capturing audio from an audio device and processing it. +// It returns a function that can be used to stop the device and any errors that occur. +func (r *Revid) startAudioDevice() (func() error, error) { + // Create audio device. + ac := &audio.Config{ + SampleRate: r.config.SampleRate, + Channels: r.config.Channels, + RecPeriod: r.config.RecPeriod, + BitDepth: r.config.BitDepth, + Codec: r.config.InputCodec, + } + mts.Meta.Add("sampleRate", strconv.Itoa(r.config.SampleRate)) + mts.Meta.Add("channels", strconv.Itoa(r.config.Channels)) + mts.Meta.Add("period", fmt.Sprintf("%.6f", r.config.RecPeriod)) + mts.Meta.Add("bitDepth", strconv.Itoa(r.config.BitDepth)) + switch r.config.InputCodec { + case codecutil.PCM: + mts.Meta.Add("codec", "pcm") + case codecutil.ADPCM: + mts.Meta.Add("codec", "adpcm") + default: + r.config.Logger.Log(logger.Fatal, pkg+"no audio codec set in config") + } + + ai, err := audio.NewDevice(ac, r.config.Logger) + if err != nil { + r.config.Logger.Log(logger.Fatal, pkg+"failed to create audio device", "error", err.Error()) + } + + // Start audio device + err = ai.Start() + if err != nil { + r.config.Logger.Log(logger.Fatal, pkg+"failed to start audio device", "error", err.Error()) + } + + // Process output from audio device. + r.config.ChunkSize = ai.ChunkSize() + r.wg.Add(1) + go r.processFrom(ai, time.Duration(float64(time.Second)/r.config.WriteRate)) + return func() error { + ai.Stop() + return nil + }, nil +} diff --git a/revid/revid.go b/revid/revid.go index 410db7a2..75c9104e 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -45,7 +45,6 @@ import ( "bitbucket.org/ausocean/av/codec/h265" "bitbucket.org/ausocean/av/container/flv" "bitbucket.org/ausocean/av/container/mts" - "bitbucket.org/ausocean/av/input/audio" "bitbucket.org/ausocean/av/protocol/rtcp" "bitbucket.org/ausocean/av/protocol/rtp" "bitbucket.org/ausocean/av/protocol/rtsp" @@ -625,51 +624,6 @@ func (r *Revid) setupInputForFile() (func() error, error) { return func() error { return f.Close() }, nil } -// startAudioDevice is used to start capturing audio from an audio device and processing it. -// It returns a function that can be used to stop the device and any errors that occur. -func (r *Revid) startAudioDevice() (func() error, error) { - // Create audio device. - ac := &audio.Config{ - SampleRate: r.config.SampleRate, - Channels: r.config.Channels, - RecPeriod: r.config.RecPeriod, - BitDepth: r.config.BitDepth, - Codec: r.config.InputCodec, - } - mts.Meta.Add("sampleRate", strconv.Itoa(r.config.SampleRate)) - mts.Meta.Add("channels", strconv.Itoa(r.config.Channels)) - mts.Meta.Add("period", fmt.Sprintf("%.6f", r.config.RecPeriod)) - mts.Meta.Add("bitDepth", strconv.Itoa(r.config.BitDepth)) - switch r.config.InputCodec { - case codecutil.PCM: - mts.Meta.Add("codec", "pcm") - case codecutil.ADPCM: - mts.Meta.Add("codec", "adpcm") - default: - r.config.Logger.Log(logger.Fatal, pkg+"no audio codec set in config") - } - - ai, err := audio.NewDevice(ac, r.config.Logger) - if err != nil { - r.config.Logger.Log(logger.Fatal, pkg+"failed to create audio device", "error", err.Error()) - } - - // Start audio device - err = ai.Start() - if err != nil { - r.config.Logger.Log(logger.Fatal, pkg+"failed to start audio device", "error", err.Error()) - } - - // Process output from audio device. - r.config.ChunkSize = ai.ChunkSize() - r.wg.Add(1) - go r.processFrom(ai, time.Duration(float64(time.Second)/r.config.WriteRate)) - return func() error { - ai.Stop() - return nil - }, nil -} - // startRTSPCamera uses RTSP to request an RTP stream from an IP camera. An RTP // client is created from which RTP packets containing either h264/h265 can read // by the selected lexer. From 2597556e6d5f8b96188c1bbc8d6296e2f2ca9ade Mon Sep 17 00:00:00 2001 From: Alan Noble Date: Thu, 8 Aug 2019 14:57:09 +0930 Subject: [PATCH 2/4] Add missing packages for Linux. --- revid/audio_linux.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/revid/audio_linux.go b/revid/audio_linux.go index 3224ce68..4df3500b 100644 --- a/revid/audio_linux.go +++ b/revid/audio_linux.go @@ -1,8 +1,14 @@ package revid import ( + "fmt" + "strconv" + "time" + + "bitbucket.org/ausocean/av/codec/codecutil" "bitbucket.org/ausocean/av/container/mts" "bitbucket.org/ausocean/av/input/audio" + "bitbucket.org/ausocean/utils/logger" ) // startAudioDevice is used to start capturing audio from an audio device and processing it. From dec7bd4870d42d5ca232c7c1fc42682a811dd3b2 Mon Sep 17 00:00:00 2001 From: scruzin Date: Thu, 8 Aug 2019 15:01:16 +0930 Subject: [PATCH 3/4] Initial revision. --- revid/audio_windows.go | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 revid/audio_windows.go diff --git a/revid/audio_windows.go b/revid/audio_windows.go new file mode 100644 index 00000000..d8b1c95e --- /dev/null +++ b/revid/audio_windows.go @@ -0,0 +1,7 @@ +// startAudioDevice is used to start capturing audio from an audio device +// TODO: Implement on Windows. +package revid + +func (r *Revid) startAudioDevice() (func() error, error) { + panic("Audio not implemented on Windows") +} From ab6c789c34be349464dc861b61f3e3de764dee06 Mon Sep 17 00:00:00 2001 From: scruzin Date: Thu, 8 Aug 2019 15:23:09 +0930 Subject: [PATCH 4/4] Added license. --- revid/audio_linux.go | 18 ++++++++++++++++++ revid/audio_windows.go | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/revid/audio_linux.go b/revid/audio_linux.go index 4df3500b..831ef077 100644 --- a/revid/audio_linux.go +++ b/revid/audio_linux.go @@ -1,3 +1,21 @@ +/* +LICENSE + Copyright (C) 2019 the Australian Ocean Lab (AusOcean) + + This is free software: you can redistribute it and/or modify them + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + in gpl.txt. If not, see http://www.gnu.org/licenses. +*/ + package revid import ( diff --git a/revid/audio_windows.go b/revid/audio_windows.go index d8b1c95e..bdc61da8 100644 --- a/revid/audio_windows.go +++ b/revid/audio_windows.go @@ -1,3 +1,21 @@ +/* +LICENSE + Copyright (C) 2019 the Australian Ocean Lab (AusOcean) + + This is free software: you can redistribute it and/or modify them + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + in gpl.txt. If not, see http://www.gnu.org/licenses. +*/ + // startAudioDevice is used to start capturing audio from an audio device // TODO: Implement on Windows. package revid