mirror of
				https://github.com/pion/mediadevices.git
				synced 2025-11-01 04:12:45 +08:00 
			
		
		
		
	Remove webrtc dependency in codec and its sub packages
This commit is contained in:
		| @@ -161,8 +161,8 @@ type mockParams struct { | ||||
| 	name string | ||||
| } | ||||
|  | ||||
| func (params *mockParams) Name() string { | ||||
| 	return params.name | ||||
| func (params *mockParams) Name() codec.Name { | ||||
| 	return codec.Name(params.name) | ||||
| } | ||||
|  | ||||
| func (params *mockParams) BuildVideoEncoder(r video.Reader, p prop.Media) (codec.ReadCloser, error) { | ||||
|   | ||||
| @@ -8,6 +8,17 @@ import ( | ||||
| 	"github.com/pion/mediadevices/pkg/prop" | ||||
| ) | ||||
|  | ||||
| // Name represents codec official name. It's possible to have more than 1 implementations | ||||
| // for the same codec name, e.g. openh264 vs x264. | ||||
| type Name string | ||||
|  | ||||
| const ( | ||||
| 	NameOpus Name = "opus" | ||||
| 	NameH264 Name = "H264" | ||||
| 	NameVP8  Name = "VP8" | ||||
| 	NameVP9  Name = "VP9" | ||||
| ) | ||||
|  | ||||
| // AudioEncoderBuilder is the interface that wraps basic operations that are | ||||
| // necessary to build the audio encoder. | ||||
| // | ||||
| @@ -15,7 +26,7 @@ import ( | ||||
| // but still giving generality for the users. | ||||
| type AudioEncoderBuilder interface { | ||||
| 	// Name represents the codec name | ||||
| 	Name() string | ||||
| 	Name() Name | ||||
| 	// BuildAudioEncoder builds audio encoder by given media params and audio input | ||||
| 	BuildAudioEncoder(r audio.Reader, p prop.Media) (ReadCloser, error) | ||||
| } | ||||
| @@ -27,7 +38,7 @@ type AudioEncoderBuilder interface { | ||||
| // but still giving generality for the users. | ||||
| type VideoEncoderBuilder interface { | ||||
| 	// Name represents the codec name | ||||
| 	Name() string | ||||
| 	Name() Name | ||||
| 	// BuildVideoEncoder builds video encoder by given media params and video input | ||||
| 	BuildVideoEncoder(r video.Reader, p prop.Media) (ReadCloser, error) | ||||
| } | ||||
|   | ||||
| @@ -4,7 +4,6 @@ import ( | ||||
| 	"github.com/pion/mediadevices/pkg/codec" | ||||
| 	"github.com/pion/mediadevices/pkg/io/video" | ||||
| 	"github.com/pion/mediadevices/pkg/prop" | ||||
| 	"github.com/pion/webrtc/v2" | ||||
| ) | ||||
|  | ||||
| // Params stores libopenh264 specific encoding parameters. | ||||
| @@ -22,8 +21,8 @@ func NewParams() (Params, error) { | ||||
| } | ||||
|  | ||||
| // Name represents the codec name | ||||
| func (p *Params) Name() string { | ||||
| 	return webrtc.H264 | ||||
| func (p *Params) Name() codec.Name { | ||||
| 	return codec.NameH264 | ||||
| } | ||||
|  | ||||
| // BuildVideoEncoder builds openh264 encoder with given params | ||||
|   | ||||
| @@ -5,7 +5,6 @@ import ( | ||||
| 	"github.com/pion/mediadevices/pkg/io/audio" | ||||
| 	"github.com/pion/mediadevices/pkg/prop" | ||||
| 	"github.com/pion/mediadevices/pkg/wave/mixer" | ||||
| 	"github.com/pion/webrtc/v2" | ||||
| ) | ||||
|  | ||||
| // Params stores opus specific encoding parameters. | ||||
| @@ -21,8 +20,8 @@ func NewParams() (Params, error) { | ||||
| } | ||||
|  | ||||
| // Name represents the codec name | ||||
| func (p *Params) Name() string { | ||||
| 	return webrtc.Opus | ||||
| func (p *Params) Name() codec.Name { | ||||
| 	return codec.NameOpus | ||||
| } | ||||
|  | ||||
| // BuildAudioEncoder builds opus encoder with given params | ||||
|   | ||||
| @@ -4,7 +4,6 @@ import ( | ||||
| 	"github.com/pion/mediadevices/pkg/codec" | ||||
| 	"github.com/pion/mediadevices/pkg/io/video" | ||||
| 	"github.com/pion/mediadevices/pkg/prop" | ||||
| 	"github.com/pion/webrtc/v2" | ||||
| ) | ||||
|  | ||||
| // ParamsVP8 stores VP8 encoding parameters. | ||||
| @@ -45,8 +44,8 @@ func NewVP8Params() (ParamsVP8, error) { | ||||
| } | ||||
|  | ||||
| // Name represents the codec name | ||||
| func (p *ParamsVP8) Name() string { | ||||
| 	return webrtc.VP8 | ||||
| func (p *ParamsVP8) Name() codec.Name { | ||||
| 	return codec.NameVP8 | ||||
| } | ||||
|  | ||||
| // BuildVideoEncoder builds VP8 encoder with given params | ||||
| @@ -114,8 +113,8 @@ func NewVP9Params() (ParamsVP9, error) { | ||||
| } | ||||
|  | ||||
| // Name represents the codec name | ||||
| func (p *ParamsVP9) Name() string { | ||||
| 	return webrtc.VP9 | ||||
| func (p *ParamsVP9) Name() codec.Name { | ||||
| 	return codec.NameVP9 | ||||
| } | ||||
|  | ||||
| // BuildVideoEncoder builds VP9 encoder with given params | ||||
|   | ||||
| @@ -59,7 +59,6 @@ import ( | ||||
| 	mio "github.com/pion/mediadevices/pkg/io" | ||||
| 	"github.com/pion/mediadevices/pkg/io/video" | ||||
| 	"github.com/pion/mediadevices/pkg/prop" | ||||
| 	"github.com/pion/webrtc/v2" | ||||
| ) | ||||
|  | ||||
| type encoder struct { | ||||
| @@ -96,8 +95,8 @@ func NewVP8Params() (VP8Params, error) { | ||||
| } | ||||
|  | ||||
| // Name represents the codec name | ||||
| func (p *VP8Params) Name() string { | ||||
| 	return webrtc.VP8 | ||||
| func (p *VP8Params) Name() codec.Name { | ||||
| 	return codec.NameVP8 | ||||
| } | ||||
|  | ||||
| // BuildVideoEncoder builds VP8 encoder with given params | ||||
| @@ -123,8 +122,8 @@ func NewVP9Params() (VP9Params, error) { | ||||
| } | ||||
|  | ||||
| // Name represents the codec name | ||||
| func (p *VP9Params) Name() string { | ||||
| 	return webrtc.VP9 | ||||
| func (p *VP9Params) Name() codec.Name { | ||||
| 	return codec.NameVP9 | ||||
| } | ||||
|  | ||||
| // BuildVideoEncoder builds VP9 encoder with given params | ||||
|   | ||||
| @@ -4,7 +4,6 @@ import ( | ||||
| 	"github.com/pion/mediadevices/pkg/codec" | ||||
| 	"github.com/pion/mediadevices/pkg/io/video" | ||||
| 	"github.com/pion/mediadevices/pkg/prop" | ||||
| 	"github.com/pion/webrtc/v2" | ||||
| ) | ||||
|  | ||||
| // Params stores libx264 specific encoding parameters. | ||||
| @@ -41,8 +40,8 @@ func NewParams() (Params, error) { | ||||
| } | ||||
|  | ||||
| // Name represents the codec name | ||||
| func (p *Params) Name() string { | ||||
| 	return webrtc.H264 | ||||
| func (p *Params) Name() codec.Name { | ||||
| 	return codec.NameH264 | ||||
| } | ||||
|  | ||||
| // BuildVideoEncoder builds x264 encoder with given params | ||||
|   | ||||
							
								
								
									
										27
									
								
								track.go
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								track.go
									
									
									
									
									
								
							| @@ -12,6 +12,15 @@ import ( | ||||
| 	"github.com/pion/webrtc/v2/pkg/media" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	webrtcCodecMapper = map[codec.Name]string{ | ||||
| 		codec.NameH264: webrtc.H264, | ||||
| 		codec.NameVP8:  webrtc.VP8, | ||||
| 		codec.NameVP9:  webrtc.VP9, | ||||
| 		codec.NameOpus: webrtc.Opus, | ||||
| 	} | ||||
| ) | ||||
|  | ||||
| // Tracker is an interface that represent MediaStreamTrack | ||||
| // Reference: https://w3c.github.io/mediacapture-main/#mediastreamtrack | ||||
| type Tracker interface { | ||||
| @@ -207,7 +216,14 @@ func newVideoEncoderBuilders(vr driver.VideoRecorder, constraints MediaTrackCons | ||||
|  | ||||
| 	encoderBuilders := make([]encoderBuilder, len(constraints.VideoEncoderBuilders)) | ||||
| 	for i, b := range constraints.VideoEncoderBuilders { | ||||
| 		encoderBuilders[i].name = b.Name() | ||||
| 		// If the codec name is not in the supported mapping, fallback to as is | ||||
| 		codecName := b.Name() | ||||
| 		mappedName, ok := webrtcCodecMapper[codecName] | ||||
| 		if ok { | ||||
| 			encoderBuilders[i].name = mappedName | ||||
| 		} else { | ||||
| 			encoderBuilders[i].name = string(codecName) | ||||
| 		} | ||||
| 		encoderBuilders[i].build = func() (codec.ReadCloser, error) { | ||||
| 			return b.BuildVideoEncoder(r, constraints.selectedMedia) | ||||
| 		} | ||||
| @@ -229,7 +245,14 @@ func newAudioEncoderBuilders(ar driver.AudioRecorder, constraints MediaTrackCons | ||||
|  | ||||
| 	encoderBuilders := make([]encoderBuilder, len(constraints.AudioEncoderBuilders)) | ||||
| 	for i, b := range constraints.AudioEncoderBuilders { | ||||
| 		encoderBuilders[i].name = b.Name() | ||||
| 		// If the codec name is not in the supported mapping, fallback to as is | ||||
| 		codecName := b.Name() | ||||
| 		mappedName, ok := webrtcCodecMapper[codecName] | ||||
| 		if ok { | ||||
| 			encoderBuilders[i].name = mappedName | ||||
| 		} else { | ||||
| 			encoderBuilders[i].name = string(codecName) | ||||
| 		} | ||||
| 		encoderBuilders[i].build = func() (codec.ReadCloser, error) { | ||||
| 			return b.BuildAudioEncoder(r, constraints.selectedMedia) | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Lukas Herman
					Lukas Herman