Skip to content

Commit

Permalink
Updated value to pointer funcs
Browse files Browse the repository at this point in the history
Renamed Intptr to Int64ptr since that is what it is and made a new
Intptr func to deal with a normal int.  Added a few others needed by
the newer structs’ properties and updated touch points as needed.
  • Loading branch information
bahern committed Mar 10, 2016
1 parent f6f7700 commit a95abdf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
20 changes: 19 additions & 1 deletion helpers/ptrs/ptrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ func Strptr(v string) *string {
return p
}

func Intptr(v int64) *int64 {
func Intptr(v int) *int {
p := new(int)
*p = v
return p
}

func Int64ptr(v int64) *int64 {
p := new(int64)
*p = v
return p
Expand All @@ -18,6 +24,18 @@ func Uintptr(v uint) *uint {
return p
}

func Uint32ptr(v uint32) *uint32 {
p := new(uint32)
*p = v
return p
}

func Uint64ptr(v uint64) *uint64 {
p := new(uint64)
*p = v
return p
}

func Boolptr(v bool) *bool {
p := new(bool)
*p = v
Expand Down
22 changes: 11 additions & 11 deletions mpd/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (m *MPD) AddNewAdaptationSetAudio(mimeType string, segmentAlignment bool, s
as := &AdaptationSet{
MimeType: Strptr(mimeType),
SegmentAlignment: Boolptr(segmentAlignment),
StartWithSAP: Intptr(startWithSAP),
StartWithSAP: Int64ptr(startWithSAP),
Lang: Strptr(lang),
}
err := m.addAdaptationSet(as)
Expand All @@ -191,7 +191,7 @@ func (m *MPD) AddNewAdaptationSetVideo(mimeType string, scanType string, segment
MimeType: Strptr(mimeType),
ScanType: Strptr(scanType),
SegmentAlignment: Boolptr(segmentAlignment),
StartWithSAP: Intptr(startWithSAP),
StartWithSAP: Int64ptr(startWithSAP),
}
err := m.addAdaptationSet(as)
if err != nil {
Expand Down Expand Up @@ -382,11 +382,11 @@ func (as *AdaptationSet) AddContentProtection(cp ContentProtectioner) error {
// timescale - sets the timescale for duration (i.e. 1000, represents milliseconds).
func (as *AdaptationSet) SetNewSegmentTemplate(duration int64, init string, media string, startNumber int64, timescale int64) (*SegmentTemplate, error) {
st := &SegmentTemplate{
Duration: Intptr(duration),
Duration: Int64ptr(duration),
Initialization: Strptr(init),
Media: Strptr(media),
StartNumber: Intptr(startNumber),
Timescale: Intptr(timescale),
StartNumber: Int64ptr(startNumber),
Timescale: Int64ptr(timescale),
}

err := as.setSegmentTemplate(st)
Expand Down Expand Up @@ -419,8 +419,8 @@ func (as *AdaptationSet) setSegmentTemplate(st *SegmentTemplate) error {
// id - ID for this representation, will get used as $RepresentationID$ in template strings.
func (as *AdaptationSet) AddNewRepresentationAudio(samplingRate int64, bandwidth int64, codecs string, id string) (*Representation, error) {
r := &Representation{
AudioSamplingRate: Intptr(samplingRate),
Bandwidth: Intptr(bandwidth),
AudioSamplingRate: Int64ptr(samplingRate),
Bandwidth: Int64ptr(bandwidth),
Codecs: Strptr(codecs),
ID: Strptr(id),
}
Expand All @@ -441,12 +441,12 @@ func (as *AdaptationSet) AddNewRepresentationAudio(samplingRate int64, bandwidth
// height - height of the video (i.e 720).
func (as *AdaptationSet) AddNewRepresentationVideo(bandwidth int64, codecs string, id string, frameRate string, width int64, height int64) (*Representation, error) {
r := &Representation{
Bandwidth: Intptr(bandwidth),
Bandwidth: Int64ptr(bandwidth),
Codecs: Strptr(codecs),
ID: Strptr(id),
FrameRate: Strptr(frameRate),
Width: Intptr(width),
Height: Intptr(height),
Width: Int64ptr(width),
Height: Int64ptr(height),
}

err := as.addRepresentation(r)
Expand All @@ -461,7 +461,7 @@ func (as *AdaptationSet) AddNewRepresentationVideo(bandwidth int64, codecs strin
// id - ID for this representation, will get used as $RepresentationID$ in template strings.
func (as *AdaptationSet) AddNewRepresentationSubtitle(bandwidth int64, id string) (*Representation, error) {
r := &Representation{
Bandwidth: Intptr(bandwidth),
Bandwidth: Int64ptr(bandwidth),
ID: Strptr(id),
}

Expand Down
4 changes: 2 additions & 2 deletions mpd/mpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *MPDSuite) TestAddNewAdaptationSetAudio() {
MPD: m,
MimeType: Strptr(VALID_MIME_TYPE_AUDIO),
SegmentAlignment: Boolptr(VALID_SEGMENT_ALIGNMENT),
StartWithSAP: Intptr(VALID_START_WITH_SAP),
StartWithSAP: Int64ptr(VALID_START_WITH_SAP),
Lang: Strptr(VALID_LANG),
}
assert.Equal(s.T(), expectedAS, as)
Expand All @@ -175,7 +175,7 @@ func (s *MPDSuite) TestAddNewAdaptationSetVideo() {
MimeType: Strptr(VALID_MIME_TYPE_VIDEO),
ScanType: Strptr(VALID_SCAN_TYPE),
SegmentAlignment: Boolptr(VALID_SEGMENT_ALIGNMENT),
StartWithSAP: Intptr(VALID_START_WITH_SAP),
StartWithSAP: Int64ptr(VALID_START_WITH_SAP),
}
assert.Equal(s.T(), expectedAS, as)
}
Expand Down
8 changes: 4 additions & 4 deletions mpd/segment_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func getSegmentListMPD() *MPD {
ra, _ := aas.AddNewRepresentationAudio(48000, 255000, "mp4a.40.2", "audio_1")

asl := new(SegmentList)
asl.Timescale = uint32ptr(48000)
asl.Duration = uint32ptr(479232)
asl.Timescale = ptrs.Uint32ptr(48000)
asl.Duration = ptrs.Uint32ptr(479232)
asl.Initialization = &URL{SourceURL: ptrs.Strptr("b4324d65-ad06-4735-9535-5cd4af84ebb6/dcb11457-9092-4410-b204-67b3c6d9a9e2/init.m4f")}

asegs := []*SegmentURL{}
Expand All @@ -56,8 +56,8 @@ func getSegmentListMPD() *MPD {
va, _ := vas.AddNewRepresentationVideo(int64(4172274), "avc1.640028", "video_1", "30000/1001", int64(1280), int64(720))

vsl := new(SegmentList)
vsl.Timescale = uint32ptr(30000)
vsl.Duration = uint32ptr(225120)
vsl.Timescale = ptrs.Uint32ptr(30000)
vsl.Duration = ptrs.Uint32ptr(225120)
vsl.Initialization = &URL{SourceURL: ptrs.Strptr("b4324d65-ad06-4735-9535-5cd4af84ebb6/f2ad47b2-5362-46e6-ad1d-dff7b10f00b8/init.m4f")}

vsegs := []*SegmentURL{}
Expand Down
34 changes: 8 additions & 26 deletions mpd/segment_timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,59 +39,41 @@ func getSegmentTimelineMPD() *MPD {
ra, _ := aas.AddNewRepresentationAudio(48000, 255000, "mp4a.40.2", "audio_1")

ast := &SegmentTemplate{
Timescale: ptrs.Intptr(48000),
Timescale: ptrs.Int64ptr(48000),
Initialization: ptrs.Strptr("audio/init.m4f"),
Media: ptrs.Strptr("audio/segment$Number$.m4f"),
SegmentTimeline: new(SegmentTimeline),
}
ra.SegmentTemplate = ast

asegs := []*SegmentTimelineSegment{}
asegs = append(asegs, &SegmentTimelineSegment{StartTime: uint64ptr(0), Duration: 231424})
asegs = append(asegs, &SegmentTimelineSegment{RepeatCount: intptr(2), Duration: 479232})
asegs = append(asegs, &SegmentTimelineSegment{StartTime: ptrs.Uint64ptr(0), Duration: 231424})
asegs = append(asegs, &SegmentTimelineSegment{RepeatCount: ptrs.Intptr(2), Duration: 479232})
asegs = append(asegs, &SegmentTimelineSegment{Duration: 10240})
asegs = append(asegs, &SegmentTimelineSegment{Duration: 247808})
asegs = append(asegs, &SegmentTimelineSegment{RepeatCount: intptr(1), Duration: 479232})
asegs = append(asegs, &SegmentTimelineSegment{RepeatCount: ptrs.Intptr(1), Duration: 479232})
asegs = append(asegs, &SegmentTimelineSegment{Duration: 3072})
ast.SegmentTimeline.Segments = asegs

vas, _ := m.AddNewAdaptationSetVideo("video/mp4", "progressive", true, 1)
va, _ := vas.AddNewRepresentationVideo(int64(4172274), "avc1.640028", "video_1", "30000/1001", int64(1280), int64(720))

vst := &SegmentTemplate{
Timescale: ptrs.Intptr(30000),
Timescale: ptrs.Int64ptr(30000),
Initialization: ptrs.Strptr("video/init.m4f"),
Media: ptrs.Strptr("video/segment$Number$.m4f"),
SegmentTimeline: new(SegmentTimeline),
}
va.SegmentTemplate = vst

vsegs := []*SegmentTimelineSegment{}
vsegs = append(vsegs, &SegmentTimelineSegment{StartTime: uint64ptr(0), Duration: 145145})
vsegs = append(vsegs, &SegmentTimelineSegment{RepeatCount: intptr(2), Duration: 270270})
vsegs = append(vsegs, &SegmentTimelineSegment{StartTime: ptrs.Uint64ptr(0), Duration: 145145})
vsegs = append(vsegs, &SegmentTimelineSegment{RepeatCount: ptrs.Intptr(2), Duration: 270270})
vsegs = append(vsegs, &SegmentTimelineSegment{Duration: 91091})
vsegs = append(vsegs, &SegmentTimelineSegment{Duration: 125125})
vsegs = append(vsegs, &SegmentTimelineSegment{RepeatCount: intptr(1), Duration: 270270})
vsegs = append(vsegs, &SegmentTimelineSegment{RepeatCount: ptrs.Intptr(1), Duration: 270270})
vsegs = append(vsegs, &SegmentTimelineSegment{Duration: 88088})
vst.SegmentTimeline.Segments = vsegs

return m
}

func intptr(v int) *int {
p := new(int)
*p = v
return p
}

func uint32ptr(v uint32) *uint32 {
p := new(uint32)
*p = v
return p
}

func uint64ptr(v uint64) *uint64 {
p := new(uint64)
*p = v
return p
}

0 comments on commit a95abdf

Please sign in to comment.