Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.

Conversation

vishal24tuniki
Copy link
Contributor

Adding feature as per SCTE standards
Ref : http://www.scte.org/documents/pdf/standards/SCTE%2067%202014.pdf 12.1.6.1 HLS Cue Tags

@vishal24tuniki
Copy link
Contributor Author

Hey @grafov any plan on merging this code ? Anything more needed from my end ?

@bradleyfalzon
Copy link
Collaborator

We'd also like to see this get merged, but a few personal queries/comments:

  1. Acronyms such as SCTE should be written as SCTE instead of Scte (eg URI is used in other variables, not Uri), such as SetScte and MediaSegment.ScteData
  2. Where there's ScteData, perhaps it should be renamed to SCTECue - as (I believe, but correct me if I'm wrong) it contains the SCTE Cue attribute, as the SCTE standard also supports ID and Time attributes, and may contain other tags in the future, therefore SCTECue maybe a more suitable name.
  3. Missing some unit tests for the reader and writer, I know this package is missing many, but I think this PR would easily support some (I can assist but not for a few days).

@vishal24tuniki
Copy link
Contributor Author

sure @bradleyfalzon I will do whatever i can from my end

@grafov
Copy link
Owner

grafov commented Mar 13, 2016

Sorry for delays too busy. I will merge it after small check ASAP.

@bradleyfalzon
Copy link
Collaborator

I'm also thinking that these SCTE tags should be added to it's own struct, such as:

type MediaSegment struct {
    SeqId           uint64
    Title           string
    URI             string
    Duration        float64
    Limit           int64
    Offset          int64
    Key             *Key
    Map             *Map
    SCTE            *SCTE
    Discontinuity   bool
    ProgramDateTime time.Time
}

type SCTE struct {
    Cue string
    ID string
    Time time.Time
}

This way it's easier to add extra tags in the future, and contains all SCTE in the same way it's done for Key and Map. This is a slightly more substantial change to the code, but I think it's straight forward to do and makes sense in relation to how other optional tags are handled.

Thoughts?

@vishal24tuniki
Copy link
Contributor Author

@bradleyfalzon makes perfect sense. Will do these changes in an hour or two and update the pull request

@vishal24tuniki
Copy link
Contributor Author

Hey guys @bradleyfalzon @grafov done withe changes as discussed above

for _, sep := range scteData {
SCTEData := strings.Split(line[12:], ",")
state.scte = new(SCTE)
for _, sep := range SCTEData {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this for loop use the decodeParamsLine, similar to the EXT-X-KEY on line 396? Or is there a quoting issue? As I think this loop expects an example line to look like #EXT-SCTE35: CUE=SOMEDATA,ID=SOMEID,TIME=3.142, whereas the example in http://www.scte.org/documents/pdf/standards/SCTE%2067%202014.pdf shows the fields should be quoted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so, i will look up that function after some time and make use of it/ write something similar for our purpose

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies, the for loop does correctly handle quotes for strings, and no quotes for float, which is expected - sorry for the confusion. But I think decodeParamsLine may still be suitable, such as:

    case !state.tagSCTE35 && strings.HasPrefix(line, "#EXT-SCTE35:"):
        state.tagSCTE35 = true
        state.listType = MEDIA
        state.scte = new(SCTE)
        for k, v := range decodeParamsLine(line[12:]) {
            switch k {
            case "CUE":
                state.scte.Cue = v
            case "ID":
                state.scte.ID = v
            case "TIME":
                state.scte.Time, _ = strconv.ParseFloat(v, 64)
            }
        }

Which handles a sample playlist like this nicely:

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:00001
#EXTINF:9.9,
http://server-host/path/file44.ts
#EXTINF:4.2,
http://server-host/path/file45.ts
#EXT-SCTE35: CUE="/DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA=="
#EXTINF:10
stream_med_00001.ts
#EXTINF:4,
stream_med_00002.ts
#EXT-SCTE35: CUE="/DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==", ID="someidentifier1", TIME=3.142
#EXTINF:6,
stream_med_00003.ts
#EXTINF:4,
stream_med_00004.ts
#EXT-SCTE35: CUE="/DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==", ID="someidentifier2", TIME="3.142"
#EXTINF:6,
stream_med_00005.ts
#EXTINF:6,
stream_med_00006.ts
#EXT-SCTE35:CUE="/DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==",ID="someidentifier3",TIME="3.142"
#EXTINF:6,
stream_med_00007.ts
#EXT-X-ENDLIST

Thanks again for these minor changes, the PR is useful and we are thankful for it, feel free to add yourself to the AUTHORS file too, if not, we'll add it at a later stage.

@bradleyfalzon
Copy link
Collaborator

New PR looks good, I've added a comment re decoding.

I'd love to see a good unit test for this as well for the reader and writer changes as I think it would provide a lot of value to see how this is expected to be used. Perhaps adding an example in sample-playlists folder (just a couple EXT-SCTE35 tags with just CUE tag and one with CUE+ID+TIME) and adding a test to reader_test.go and writer_test.go to verify it's behaving correctly. I can assist an example once you clarify the decoding comment (so I know that quoting should be required).

@vishal24tuniki
Copy link
Contributor Author

Hey @bradleyfalzon done with the changes :)

@bradleyfalzon
Copy link
Collaborator

Brilliant, looks good will test and merge hopefully within the next 12 hours.

I didn't notice before, but it looks like this is just reader methods, not writer, I can add them in at a later stage, something like the following (can you double check my suggestion) but with tests. Did you have plans to add that in the future, if not, I can.

--- a/writer.go+++ b/writer.go
@@ -449,6 +449,22 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {
                if p.winsize > 0 { // skip for VOD playlists, where winsize = 0
                        i++
                }
+               if seg.SCTE != nil {
+                       p.buf.WriteString("#EXT-X-SCTE:")
+                       p.buf.WriteString("CUE=\"")
+                       p.buf.WriteString(seg.SCTE.Cue)
+                       p.buf.WriteRune('"')
+                       if seg.SCTE.ID != "" {
+                               p.buf.WriteString(",ID=\"")
+                               p.buf.WriteString(seg.SCTE.ID)
+                               p.buf.WriteRune('"')
+                       }
+                       if seg.SCTE.Time != 0 {
+                               p.buf.WriteString(",TIME=")
+                               p.buf.WriteString(strconv.FormatFloat(seg.SCTE.Time, 'f', 3, 64))
+                       }
+                       p.buf.WriteRune('\n')
+               }
                // check for key change
                if seg.Key != nil && p.Key != seg.Key {
                        p.buf.WriteString("#EXT-X-KEY:")

@vishal24tuniki
Copy link
Contributor Author

@bradleyfalzon Yeah, please go ahead and add the writer code. I just didn't go much through the writer methods, but your code gave me a good idea. Just 1 suggestion, i feel you should use precision as -1 instead of 3, which would help to reform the float64 variable Time back

Refer : https://golang.org/pkg/strconv/#FormatFloat
(The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.)

I can create another PR for writer test cases later

bradleyfalzon added a commit that referenced this pull request Mar 17, 2016
Parsing SCTE35 tag from playlist
@bradleyfalzon bradleyfalzon merged commit 027badc into grafov:master Mar 17, 2016
@bradleyfalzon
Copy link
Collaborator

@vishal24tuniki
Copy link
Contributor Author

@bradleyfalzon interesting ! Will go through them in next couple of days

grafov pushed a commit that referenced this pull request Nov 22, 2016
Parsing SCTE35 tag from playlist
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants