Skip to content

Commit

Permalink
Merge pull request #152 from TheCacophonyProject/add-audio-seed
Browse files Browse the repository at this point in the history
Add audio seed
  • Loading branch information
gferraro authored Oct 28, 2024
2 parents 5c3c924 + f562c06 commit 1f5715b
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 643 deletions.
41 changes: 40 additions & 1 deletion api/audiorecording.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package api
import (
"encoding/json"
"net/http"
"strconv"

goconfig "github.com/TheCacophonyProject/go-config"
"github.com/godbus/dbus"
Expand All @@ -34,6 +35,7 @@ func (api *ManagementAPI) GetAudioRecording(w http.ResponseWriter, r *http.Reque
}
type AudioRecording struct {
AudioMode string `json:"audio-mode"`
AudioSeed string `json:"audio-seed"`
}

w.WriteHeader(http.StatusOK)
Expand All @@ -46,11 +48,23 @@ func (api *ManagementAPI) GetAudioRecording(w http.ResponseWriter, r *http.Reque
func (api *ManagementAPI) SetAudioRecording(w http.ResponseWriter, r *http.Request) {
log.Println("update audio recording")
audioMode := r.FormValue("audio-mode")
stringSeed := r.FormValue("audio-seed")
var audioSeed uint32
if stringSeed == "" {
audioSeed = 0
} else {
seed, err := strconv.ParseUint(r.FormValue("audio-seed"), 10, 32)
if err != nil {
badRequest(&w, err)
return
}
audioSeed = uint32(seed)
}

audioRecording := goconfig.AudioRecording{
AudioMode: audioMode,
AudioSeed: audioSeed,
}

if err := api.config.Set(goconfig.AudioRecordingKey, &audioRecording); err != nil {
serverError(&w, err)
}
Expand Down Expand Up @@ -79,6 +93,31 @@ func (api *ManagementAPI) AudioRecordingStatus(w http.ResponseWriter, r *http.Re

}

func (api *ManagementAPI) TakeLongAudioRecording(w http.ResponseWriter, r *http.Request) {
tc2AgentDbus, err := getTC2AgentDbus()
if err != nil {
log.Println(err)
http.Error(w, "Failed to connect to DBus", http.StatusInternalServerError)
return
}
seconds, err := strconv.ParseUint(r.URL.Query().Get("seconds"), 10, 32)
if err != nil {
badRequest(&w, err)
return
}
var result string

err = tc2AgentDbus.Call("org.cacophony.TC2Agent.longaudiorecording", 0, seconds).Store(&result)
if err != nil {
log.Println(err)
http.Error(w, "Failed to request 5 minute audio recording", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)

json.NewEncoder(w).Encode(result)
}

func (api *ManagementAPI) TakeTestAudioRecording(w http.ResponseWriter, r *http.Request) {
tc2AgentDbus, err := getTC2AgentDbus()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/managementd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func main() {

apiRouter.HandleFunc("/audiorecording", apiObj.SetAudioRecording).Methods("POST")
apiRouter.HandleFunc("/audiorecording", apiObj.GetAudioRecording).Methods("GET")
apiRouter.HandleFunc("/audio/long-recording", apiObj.TakeLongAudioRecording).Methods("PUT")
apiRouter.HandleFunc("/audio/test-recording", apiObj.TakeTestAudioRecording).Methods("PUT")
apiRouter.HandleFunc("/audio/audio-status", apiObj.AudioRecordingStatus).Methods("GET")
apiRouter.HandleFunc("/audio/recordings", apiObj.GetAudioRecordings).Methods("GET")
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@ require (
)

require (
github.com/TheCacophonyProject/event-reporter/v3 v3.8.0 // indirect
github.com/TheCacophonyProject/event-reporter/v3 v3.8.1 // indirect
github.com/TheCacophonyProject/window v0.0.0-20200312071457-7fc8799fdce7 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gobuffalo/envy v1.10.2 // indirect
github.com/gobuffalo/packd v1.0.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/sys v0.25.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
Expand Down
Loading

0 comments on commit 1f5715b

Please sign in to comment.