-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f577fe0
commit fd5a23e
Showing
12 changed files
with
398 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,127 @@ | ||
package moqt | ||
|
||
import "github.com/OkutaniDaichi0106/gomoqt/internal/transport" | ||
|
||
// /* | ||
// * data interface is implemented by dataReceiveStream and receivedDatagram. | ||
// */ | ||
// type data interface { | ||
// Group | ||
// io.Reader | ||
// } | ||
|
||
type dataFragment interface { | ||
|
||
// | ||
SubscribeID() SubscribeID | ||
TrackPriority() TrackPriority | ||
GroupOrder() GroupOrder | ||
|
||
// | ||
GroupPriority() GroupPriority | ||
GroupSequence() GroupSequence | ||
|
||
Payload() []byte | ||
} | ||
|
||
var _ dataFragment = (*streamDataFragment)(nil) | ||
|
||
type streamDataFragment struct { | ||
trackPriority TrackPriority | ||
groupOrder GroupOrder | ||
|
||
streamID transport.StreamID | ||
receivedGroup | ||
payload []byte | ||
} | ||
|
||
func (d streamDataFragment) StreamID() transport.StreamID { | ||
return d.streamID | ||
} | ||
|
||
func (d streamDataFragment) TrackPriority() TrackPriority { | ||
return d.trackPriority | ||
} | ||
|
||
func (d streamDataFragment) GroupOrder() GroupOrder { | ||
return d.groupOrder | ||
} | ||
|
||
func (d streamDataFragment) Payload() []byte { | ||
return d.payload | ||
} | ||
|
||
var _ dataFragment = (*datagramData)(nil) | ||
|
||
type datagramData struct { | ||
trackPriority TrackPriority | ||
groupOrder GroupOrder | ||
|
||
receivedGroup | ||
payload []byte | ||
} | ||
|
||
func (d datagramData) TrackPriority() TrackPriority { | ||
return d.trackPriority | ||
} | ||
|
||
func (d datagramData) GroupOrder() GroupOrder { | ||
return d.groupOrder | ||
} | ||
|
||
func (d datagramData) Payload() []byte { | ||
return d.payload | ||
} | ||
|
||
/* | ||
* dataQueue implements heap.Interface. | ||
*/ | ||
type dataQueue []dataFragment | ||
|
||
func (q dataQueue) Len() int { | ||
return len(q) | ||
} | ||
|
||
func (q dataQueue) Less(i, j int) bool { | ||
return schedule(q[i], q[j]) | ||
} | ||
|
||
func (q dataQueue) Swap(i, j int) { | ||
q[i], q[j] = q[j], q[i] | ||
} | ||
|
||
func (q *dataQueue) Push(x interface{}) { | ||
*q = append(*q, x.(dataFragment)) | ||
} | ||
|
||
func (q *dataQueue) Pop() interface{} { | ||
old := *q | ||
n := len(old) | ||
x := old[n-1] | ||
*q = old[:n-1] | ||
return x | ||
} | ||
|
||
func schedule(a, b dataFragment) bool { | ||
if a.SubscribeID() != b.SubscribeID() { | ||
if a.TrackPriority() != b.TrackPriority() { | ||
return a.TrackPriority() < b.TrackPriority() | ||
} | ||
} | ||
|
||
if a.GroupPriority() != b.GroupPriority() { | ||
return a.GroupPriority() < b.GroupPriority() | ||
} | ||
|
||
switch a.GroupOrder() { | ||
case DEFAULT: | ||
return true | ||
case ASCENDING: | ||
return a.GroupSequence() < b.GroupSequence() | ||
case DESCENDING: | ||
return a.GroupSequence() > b.GroupSequence() | ||
default: | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.