mirror of https://bitbucket.org/ausocean/av.git
Merge branch 'compile-on-windows' of https://bitbucket.org/ausocean/av into compile-on-windows
This commit is contained in:
commit
11e6d55f49
|
@ -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
|
||||
}
|
|
@ -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"
|
||||
|
@ -631,51 +630,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.
|
||||
|
|
Loading…
Reference in New Issue