Skip to content

Commit 29ac0bf

Browse files
committed
Merge branch 'ffmpeg61' of github.com:djthorpe/go-media into ffmpeg61
2 parents e5846d7 + 43415b5 commit 29ac0bf

File tree

5 files changed

+85
-17
lines changed

5 files changed

+85
-17
lines changed

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/mutablelogic/go-media
22

3-
go 1.22
4-
5-
toolchain go1.22.4
3+
go 1.20
64

75
require (
86
github.com/alecthomas/kong v0.9.0

manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ type Format interface {
109109

110110
// The unique name that the format can be referenced as
111111
Name() string
112+
113+
// Description of the format
114+
Description() string
112115
}
113116

114117
// A container format for a media file, reader, device or

pkg/ffmpeg/format.go

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package ffmpeg
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"strings"
76

87
// Packages
@@ -35,6 +34,8 @@ type metaDevice struct {
3534
Default bool `json:"default,omitempty"`
3635
}
3736

37+
var _ media.Format = &Format{}
38+
3839
///////////////////////////////////////////////////////////////////////////////
3940
// LIFECYCLE
4041

@@ -50,14 +51,36 @@ func newInputFormats(demuxer *ff.AVInputFormat, t media.Type) []media.Format {
5051
})
5152
}
5253

54+
if !t.Is(media.DEVICE) {
55+
return result
56+
}
57+
5358
// Get devices
54-
if t.Is(media.DEVICE) {
55-
list, err := ff.AVDevice_list_input_sources(demuxer, "", nil)
56-
if err == nil {
57-
fmt.Println(list)
58-
}
59+
list, err := ff.AVDevice_list_input_sources(demuxer, "", nil)
60+
if err != nil {
61+
// Bail out if we can't get the list of devices
62+
return result
63+
}
64+
defer ff.AVDevice_free_list_devices(list)
65+
66+
// Make device list
67+
devices := make([]*Device, 0, list.NumDevices())
68+
for i, device := range list.Devices() {
69+
devices = append(devices, &Device{
70+
metaDevice{
71+
Name: device.Name(),
72+
Description: device.Description(),
73+
Default: list.Default() == i,
74+
},
75+
})
76+
}
77+
78+
// Append to result
79+
for _, format := range result {
80+
format.(*Format).Devices = devices
5981
}
6082

83+
// Return result
6184
return result
6285
}
6386

@@ -71,14 +94,36 @@ func newOutputFormats(muxer *ff.AVOutputFormat, t media.Type) []media.Format {
7194
})
7295
}
7396

97+
if !t.Is(media.DEVICE) {
98+
return result
99+
}
100+
74101
// Get devices
75-
if t.Is(media.DEVICE) {
76-
dict := ff.AVUtil_dict_alloc()
77-
defer ff.AVUtil_dict_free(dict)
78-
list, err := ff.AVDevice_list_output_sinks(muxer, "", dict)
79-
fmt.Println(err, list, dict)
102+
list, err := ff.AVDevice_list_output_sinks(muxer, "", nil)
103+
if err != nil {
104+
// Bail out if we can't get the list of devices
105+
return result
106+
}
107+
defer ff.AVDevice_free_list_devices(list)
108+
109+
// Make device list
110+
devices := make([]*Device, 0, list.NumDevices())
111+
for i, device := range list.Devices() {
112+
devices = append(devices, &Device{
113+
metaDevice{
114+
Name: device.Name(),
115+
Description: device.Description(),
116+
Default: list.Default() == i,
117+
},
118+
})
119+
}
120+
121+
// Append to result
122+
for _, format := range result {
123+
format.(*Format).Devices = devices
80124
}
81125

126+
// Return result
82127
return result
83128
}
84129

@@ -100,3 +145,14 @@ func (f *Format) Type() media.Type {
100145
func (f *Format) Name() string {
101146
return f.metaFormat.Name
102147
}
148+
149+
func (f *Format) Description() string {
150+
switch {
151+
case f.Input != nil:
152+
return f.Input.LongName()
153+
case f.Output != nil:
154+
return f.Output.LongName()
155+
default:
156+
return f.metaFormat.Name
157+
}
158+
}

sys/ffmpeg61/avdevice.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,30 @@ func (ctx *AVDeviceInfo) String() string {
6969
////////////////////////////////////////////////////////////////////////////////
7070
// PROPERTIES
7171

72+
// list of autodetected devices
7273
func (ctx *AVDeviceInfoList) Devices() []*AVDeviceInfo {
73-
if ctx.nb_devices == 0 || ctx.devices == nil {
74+
if ctx == nil || ctx.nb_devices == 0 || ctx.devices == nil {
7475
return nil
7576
}
7677
return cAVDeviceInfoSlice(unsafe.Pointer(ctx.devices), ctx.nb_devices)
7778
}
7879

80+
// number of autodetected devices
7981
func (ctx *AVDeviceInfoList) NumDevices() int {
82+
if ctx == nil {
83+
return 0
84+
}
8085
return int(ctx.nb_devices)
8186
}
8287

88+
// index of default device or -1 if no default
89+
func (ctx *AVDeviceInfoList) Default() int {
90+
if ctx == nil {
91+
return -1
92+
}
93+
return int(ctx.default_device)
94+
}
95+
8396
func (ctx *AVDeviceInfo) Name() string {
8497
return C.GoString(ctx.device_name)
8598
}

sys/ffmpeg61/avdevice_input.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ffmpeg
22

33
import (
4-
"fmt"
54
"unsafe"
65
)
76

@@ -60,7 +59,6 @@ func AVDevice_list_input_sources(device *AVInputFormat, device_name string, devi
6059
// Get list
6160
var list *C.struct_AVDeviceInfoList
6261
if ret := int(C.avdevice_list_input_sources((*C.struct_AVInputFormat)(device), cName, dict, &list)); ret < 0 {
63-
fmt.Println("C list", device, cName, dict, list, ret)
6462
return nil, AVError(ret)
6563
}
6664

0 commit comments

Comments
 (0)