Giter Club home page Giter Club logo

Comments (3)

bradleyfalzon avatar bradleyfalzon commented on August 15, 2024

@grafov, what's your thoughts on this?

It appears to create a NewMediaPlaylist for VoD, we need to set the window size to 0 and the capacity to some large number, then call the Decode or DecodeFrom on this newly created playlist.

Such as (where media.m3u8 is a copy of sample-playlists/wowza-vod-chunklist.m3u8):

    f, err := os.Open("media.m3u8")
    if err != nil {
        fmt.Println(err)
    }
    p, err := m3u8.NewMediaPlaylist(0, 1000)
    if err != nil {
        fmt.Println(err)
    }
    err = p.DecodeFrom(bufio.NewReader(f), false)
    if err != nil {
        fmt.Println(err)
    }

    fmt.Printf("Playlist object: %+v\n", p)

If someone follows the above steps, then the playlist will be empty but PR #38 should fix the problem.

But if someone uses the following method, where they might not know ahead of time whether the playlist is a Master or Media (or even if it's VoD or Live).

    f, err := os.Open("media.m3u8")
    if err != nil {
        panic(err)
    }
    p, listType, err := m3u8.DecodeFrom(bufio.NewReader(f), true)
    if err != nil {
        panic(err)
    }
    switch listType {
    case m3u8.MEDIA:
        mediapl := p.(*m3u8.MediaPlaylist)
        fmt.Printf("%+v\n", mediapl)
    case m3u8.MASTER:
        masterpl := p.(*m3u8.MasterPlaylist)
        fmt.Printf("%+v\n", masterpl)
    }

The window size appears to be set to 8 (see

m3u8/reader.go

Line 155 in 11af315

media, err = NewMediaPlaylist(8, 1024) // TODO make it autoextendable
), and the full playlist is not shown (only 8 segments, not the full amount). I don't believe anyone can change the window size after the fact either.

So, PR #38 could be merged (I'd still like to do some additional testing though), but then we should modify the Decode methods in reader.go to set the winsize to 0 when playlist is Closed (when playlist is a VoD). For example:

--- a/reader.go
+++ b/reader.go
@@ -362,6 +362,7 @@ func decodeLineOfMediaPlaylist(p *MediaPlaylist, wv *WV, state *decodingState, l
        case line == "#EXT-X-ENDLIST":
                state.listType = MEDIA
                p.Closed = true
+               p.winsize = 0
        case strings.HasPrefix(line, "#EXT-X-VERSION:"):
                state.listType = MEDIA
                if _, err = fmt.Sscanf(line, "#EXT-X-VERSION:%d", &p.ver); strict && err != nil {

But because decodeLineOfMediaPlaylist is also used when a user may have explicitly called NewMediaPlaylist(3, 1000) the above proposal would overwrite the 3 to 0 - which may not be what the user wanted. So perhaps a better option would be to modify the Decode function to choose a different window size once the playlist has been decoded - if it's live set winsize = 8, if it's VoD, set to winsize = 0. So, I'm probably leaning towards the following:

--- a/reader.go
+++ b/reader.go
@@ -194,6 +194,9 @@ func decode(buf *bytes.Buffer, strict bool) (Playlist, ListType, error) {
        case MASTER:
                return master, MASTER, nil
        case MEDIA:
+               if media.Closed {
+                       media.winsize = 0
+               }
                return media, MEDIA, nil
        default:
                return nil, state.listType, errors.New("Can't detect playlist type")

Perhaps another PR could include options to overwrite the winsize as the decode function does set to 8, others (probably myself) might want to change this on the fly.

from m3u8.

bradleyfalzon avatar bradleyfalzon commented on August 15, 2024

I've proposed exposing the winsize as well as setting it correctly on VoD in #70.

from m3u8.

bradleyfalzon avatar bradleyfalzon commented on August 15, 2024

This should now be resolved in #70, let me know if it's not.

from m3u8.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.