Skip to content

Commit

Permalink
Merge pull request #35 from mutablelogic/ffmpeg61
Browse files Browse the repository at this point in the history
Updated logging
  • Loading branch information
djthorpe authored Jul 31, 2024
2 parents 5af5cc1 + 67e090a commit df83a43
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 3 deletions.
33 changes: 33 additions & 0 deletions pkg/ffmpeg/logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ffmpeg

import (
"fmt"
"strings"

// Packages
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
)

///////////////////////////////////////////////////////////////////////////////
// TYPES

// Logging function
type LogFn func(text string)

///////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS

// Set logging options, including a callback function
func SetLogging(verbose bool, fn LogFn) {
ff.AVUtil_log_set_level(ff.AV_LOG_INFO)
if !verbose {
ff.AVUtil_log_set_level(ff.AV_LOG_ERROR)
}
if fn != nil {
ff.AVUtil_log_set_callback(func(level ff.AVLog, message string, userInfo any) {
fn(fmt.Sprintf("[%v] %v", level, strings.TrimSpace(message)))
})
} else {
ff.AVUtil_log_set_callback(nil)
}
}
31 changes: 31 additions & 0 deletions pkg/ffmpeg/logging_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ffmpeg_test

import (
"testing"

// Packages
ffmpeg "github.com/mutablelogic/go-media/pkg/ffmpeg"
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
)

func Test_logging_001(t *testing.T) {
// Set logging
ffmpeg.SetLogging(true, func(v string) {
t.Log(v)
})

ff.AVUtil_log(nil, ff.AV_LOG_INFO, "INFO test")
ff.AVUtil_log(nil, ff.AV_LOG_WARNING, "WARN test")
ff.AVUtil_log(nil, ff.AV_LOG_ERROR, "ERROR test")
}

func Test_logging_002(t *testing.T) {
// Set logging
ffmpeg.SetLogging(false, func(v string) {
t.Log(v)
})

ff.AVUtil_log(nil, ff.AV_LOG_INFO, "INFO test")
ff.AVUtil_log(nil, ff.AV_LOG_WARNING, "WARN test")
ff.AVUtil_log(nil, ff.AV_LOG_ERROR, "ERROR test")
}
11 changes: 8 additions & 3 deletions pkg/ffmpeg/resampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,22 @@ func (r *resampler) Frame(src *Frame) (*Frame, error) {
////////////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS

//func swrConvertFrame_(ctx *ff.SWRContext, src, dest *ff.AVFrame) error {
// return ff.SWResample_convert_frame(ctx, src, dest)
//}
func swrConvertFrame(ctx *ff.SWRContext, src, dest *ff.AVFrame) error {
return ff.SWResample_convert_frame(ctx, src, dest)
}

/*
func swrConvertFrame(ctx *ff.SWRContext, src, dest *ff.AVFrame) error {
fmt.Println("swrConvertFrame", src, "=>", dest)
fmt.Println("swrConvertFrame", ff.AVUtil_samples_frame(src), "=>", ff.AVUtil_samples_frame(dest))
_, err := ff.SWResample_convert(ctx, ff.AVUtil_samples_frame(dest), ff.AVUtil_samples_frame(src))
if err != nil {
return err
}
return nil
}
*/

func newResampler(dest, src *Frame) (*ff.SWRContext, error) {
// Create a new resampler
Expand Down
27 changes: 27 additions & 0 deletions sys/ffmpeg61/avutil_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@ const (

var cbLog AVLogFunc

////////////////////////////////////////////////////////////////////////////////
// STRINGIFY

func (v AVLog) String() string {
switch v {
case AV_LOG_QUIET:
return "QUIET"
case AV_LOG_PANIC:
return "PANIC"
case AV_LOG_FATAL:
return "FATAL"
case AV_LOG_ERROR:
return "ERROR"
case AV_LOG_WARNING:
return "WARN"
case AV_LOG_INFO:
return "INFO"
case AV_LOG_VERBOSE:
return "VERBOSE"
case AV_LOG_DEBUG:
return "DEBUG"
case AV_LOG_TRACE:
return "TRACE"
}
return "[?? Invalid AVLog value]"
}

////////////////////////////////////////////////////////////////////////////////
// BINDINGS

Expand Down

0 comments on commit df83a43

Please sign in to comment.