Skip to content

Commit 7128226

Browse files
committed
Updates
1 parent 575fde6 commit 7128226

File tree

14 files changed

+50
-134
lines changed

14 files changed

+50
-134
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test: go-dep
4646
@echo ... test sys/ffmpeg61
4747
@${GO} test ./sys/ffmpeg61
4848
@echo ... test pkg/ffmpeg
49-
@${GO} test ./pkg/ffmpeg
49+
@${GO} test -v ./pkg/ffmpeg
5050
@echo ... test sys/chromaprint
5151
@${GO} test ./sys/chromaprint
5252
@echo ... test pkg/chromaprint

interfaces.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ type Manager interface {
4242
// Return supported input formats which match any filter, which can be
4343
// a name, extension (with preceeding period) or mimetype. The MediaType
4444
// can be NONE (for any) or combinations of DEVICE and STREAM.
45-
InputFormats(MediaType, ...string) []Format
45+
InputFormats(Type, ...string) []Format
4646

4747
// Return supported output formats which match any filter, which can be
4848
// a name, extension (with preceeding period) or mimetype. The MediaType
4949
// can be NONE (for any) or combinations of DEVICE and STREAM.
50-
OutputFormats(MediaType, ...string) []Format
50+
OutputFormats(Type, ...string) []Format
5151

5252
// Return supported devices for a given format.
5353
// Not all devices may be supported on all platforms or listed
@@ -105,7 +105,7 @@ type Device interface {
105105
Description() string
106106

107107
// Flags indicating the type INPUT or OUTPUT, AUDIO or VIDEO
108-
Type() MediaType
108+
Type() Type
109109

110110
// Whether this is the default device
111111
Default() bool
@@ -129,7 +129,7 @@ type Format interface {
129129

130130
// Flags indicating the type. INPUT for a demuxer or source, OUTPUT for a muxer or
131131
// sink, DEVICE for a device, FILE for a file. Plus AUDIO, VIDEO, DATA, SUBTITLE.
132-
Type() MediaType
132+
Type() Type
133133
}
134134

135135
// Media represents a media stream, which can be input or output. A new media
@@ -150,7 +150,7 @@ type Media interface {
150150

151151
// Return INPUT for a demuxer or source, OUTPUT for a muxer or
152152
// sink, DEVICE for a device, FILE for a file or stream.
153-
Type() MediaType
153+
Type() Type
154154

155155
// Return the metadata for the media, filtering by keys if any
156156
// are included. Use the "artwork" key to return only artwork.
@@ -168,7 +168,7 @@ type DecoderMapFunc func(Stream) (Parameters, error)
168168
// within a media file
169169
type Stream interface {
170170
// Return AUDIO, VIDEO, SUBTITLE or DATA
171-
Type() MediaType
171+
Type() Type
172172

173173
// Return the stream parameters
174174
Parameters() Parameters
@@ -195,7 +195,7 @@ type Parameters interface {
195195
VideoParameters
196196

197197
// Return the media type (AUDIO, VIDEO, SUBTITLE, DATA)
198-
Type() MediaType
198+
Type() Type
199199

200200
// Return the stream id for encoding, or zero if not set
201201
Id() int
@@ -254,14 +254,14 @@ type Codec interface {
254254
Description() string
255255

256256
// Return the codec type (AUDIO, VIDEO, SUBTITLE, DATA, INPUT, OUTPUT)
257-
Type() MediaType
257+
Type() Type
258258
}
259259

260260
// Packet represents a packet of demultiplexed data, or a packet
261261
// to be multiplexed.
262262
type Packet interface {
263263
// The packet can be audio, video, subtitle or data.
264-
Type() MediaType
264+
Type() Type
265265

266266
// The stream identifier for the packet
267267
Id() int

pkg/ffmpeg/frame.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66

77
// Packages
8+
media "github.com/mutablelogic/go-media"
89
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
910
)
1011

@@ -103,14 +104,14 @@ func (frame *Frame) CopyPropsFromFrame(other *Frame) error {
103104

104105
// Return frame type - AUDIO or VIDEO. Other types are not yet
105106
// identified and returned as UNKNOWN
106-
func (frame *Frame) Type() Type {
107+
func (frame *Frame) Type() media.Type {
107108
switch {
108109
case frame.SampleRate() > 0 && frame.SampleFormat() != ff.AV_SAMPLE_FMT_NONE:
109-
return AUDIO
110+
return media.AUDIO
110111
case frame.Width() > 0 && frame.Height() > 0 && frame.PixelFormat() != ff.AV_PIX_FMT_NONE:
111-
return VIDEO
112+
return media.VIDEO
112113
default:
113-
return UNKNOWN
114+
return media.UNKNOWN
114115
}
115116
}
116117

@@ -225,7 +226,7 @@ func (frame *Frame) matchesResampleResize(other *Frame) bool {
225226
return false
226227
}
227228
switch frame.Type() {
228-
case AUDIO:
229+
case media.AUDIO:
229230
if frame.SampleFormat() != other.SampleFormat() {
230231
return false
231232
}
@@ -237,7 +238,7 @@ func (frame *Frame) matchesResampleResize(other *Frame) bool {
237238
return false
238239
}
239240
return true
240-
case VIDEO:
241+
case media.VIDEO:
241242
if frame.PixelFormat() != other.PixelFormat() {
242243
return false
243244
}

pkg/ffmpeg/frame_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55

66
ffmpeg "github.com/mutablelogic/go-media/pkg/ffmpeg"
77
assert "github.com/stretchr/testify/assert"
8+
9+
// Namespace imports
10+
. "github.com/mutablelogic/go-media"
811
)
912

1013
func Test_frame_001(t *testing.T) {
@@ -26,7 +29,7 @@ func Test_frame_002(t *testing.T) {
2629
t.FailNow()
2730
}
2831
defer frame.Close()
29-
assert.Equal(ffmpeg.AUDIO, frame.Type())
32+
assert.Equal(AUDIO, frame.Type())
3033
assert.Equal(44100, frame.SampleRate())
3134
t.Log(frame)
3235
}
@@ -39,7 +42,7 @@ func Test_frame_003(t *testing.T) {
3942
t.FailNow()
4043
}
4144
defer frame.Close()
42-
assert.Equal(ffmpeg.VIDEO, frame.Type())
45+
assert.Equal(VIDEO, frame.Type())
4346
assert.Equal(1280, frame.Width())
4447
assert.Equal(720, frame.Height())
4548
t.Log(frame)

pkg/ffmpeg/image.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"image"
66

77
// Packages
8+
media "github.com/mutablelogic/go-media"
89
imagex "github.com/mutablelogic/go-media/pkg/image"
910
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
1011

@@ -60,7 +61,7 @@ func FrameFromImage(src image.Image) (*Frame, error) {
6061
// until the image is no longer required, but the image can be discarded
6162
// TODO: Add a copy flag which copies the memory?
6263
func (frame *Frame) ImageFromFrame() (image.Image, error) {
63-
if frame.Type() != VIDEO {
64+
if frame.Type() != media.VIDEO {
6465
return nil, ErrBadParameter.With("unsupported frame type: ", frame.Type())
6566
}
6667
switch frame.PixelFormat() {

pkg/ffmpeg/packet_decoder.go

Lines changed: 0 additions & 93 deletions
This file was deleted.

pkg/ffmpeg/par.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"slices"
66

77
// Packages
8+
media "github.com/mutablelogic/go-media"
89
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
910

1011
// Namespace imports
@@ -130,18 +131,18 @@ func (ctx *Par) String() string {
130131
///////////////////////////////////////////////////////////////////////////////
131132
// PUBLIC METHODS
132133

133-
func (ctx *Par) Type() Type {
134+
func (ctx *Par) Type() media.Type {
134135
switch ctx.CodecType() {
135136
case ff.AVMEDIA_TYPE_AUDIO:
136-
return AUDIO
137+
return media.AUDIO
137138
case ff.AVMEDIA_TYPE_VIDEO:
138-
return VIDEO
139+
return media.VIDEO
139140
case ff.AVMEDIA_TYPE_SUBTITLE:
140-
return SUBTITLE
141+
return media.SUBTITLE
141142
case ff.AVMEDIA_TYPE_DATA:
142-
return DATA
143+
return media.DATA
143144
default:
144-
return UNKNOWN
145+
return media.UNKNOWN
145146
}
146147
}
147148

pkg/ffmpeg/re.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package ffmpeg
33
import (
44
"errors"
55
"fmt"
6+
67
// Packages
8+
media "github.com/mutablelogic/go-media"
79
)
810

911
////////////////////////////////////////////////////////////////////////////////
@@ -12,7 +14,7 @@ import (
1214
// Re implements a resampler and rescaler for audio and video frames.
1315
// May need to extend it for subtitles later on
1416
type Re struct {
15-
t Type
17+
t media.Type
1618
audio *resampler
1719
video *rescaler
1820
}
@@ -24,13 +26,13 @@ func NewRe(par *Par, force bool) (*Re, error) {
2426
re := new(Re)
2527
re.t = par.Type()
2628
switch re.t {
27-
case AUDIO:
29+
case media.AUDIO:
2830
if audio, err := NewResampler(par, force); err != nil {
2931
return nil, err
3032
} else {
3133
re.audio = audio
3234
}
33-
case VIDEO:
35+
case media.VIDEO:
3436
if video, err := NewRescaler(par, force); err != nil {
3537
return nil, err
3638
} else {
@@ -69,9 +71,9 @@ func (re *Re) Frame(src *Frame) (*Frame, error) {
6971
}
7072
}
7173
switch re.t {
72-
case AUDIO:
74+
case media.AUDIO:
7375
return re.audio.Frame(src)
74-
case VIDEO:
76+
case media.VIDEO:
7577
return re.video.Frame(src)
7678
default:
7779
return src, nil

pkg/ffmpeg/re_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"testing"
88

9+
media "github.com/mutablelogic/go-media"
910
ffmpeg "github.com/mutablelogic/go-media/pkg/ffmpeg"
1011
assert "github.com/stretchr/testify/assert"
1112
)
@@ -88,7 +89,7 @@ func Test_re_002(t *testing.T) {
8889

8990
// Decode function
9091
decodefn := func(_ int, frame *ffmpeg.Frame) error {
91-
if frame != nil && frame.Type() != ffmpeg.AUDIO {
92+
if frame != nil && frame.Type() != media.AUDIO {
9293
return nil
9394
}
9495
resampled, err := re.Frame(frame)

0 commit comments

Comments
 (0)