-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
h264/bits: new BitReader to eventually replace BitReader in read.go #36
Conversation
…r field to BitReader
…dling of cache and to reduce allocations
…t fields and improved formatting of NewBitreader
This change included modification to cache, specifically a rename of cache.next to cache.get.
…olated into single function readBits
This is not needed, BitReader.ReadBits(8) can be used
Reverted changes that I made to files cabac.go, nalUnit.go, rbsp.go, read.go and slice.go, as the changes would make this PR too large.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the complexity of this, I think you'd be better taking the code in bzip2 and adding a PeekBits. That is a trivial addition, using essentially the same code that is in ReadBits, but first Peeking the bytes to need to read the given number of bits. That would be (untested):
func (br *bitReader) PeekBits64(bits uint) (n uint64) {
byt, err := br.r.Peek(int(n+7) / 8)
if err != nil {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
br.err = err
return 0
}
for i := 0; bits > br.bits; i++ {
b := byt[i]
if err != nil {
br.err = err
return 0
}
br.n <<= 8
br.n |= uint64(b)
br.bits += 8
}
n = (br.n >> (br.bits - bits)) & ((1 << bits) - 1)
br.bits -= bits
return
}
This requires that the copied version of bit_reader.go has the io.ByteReader
field changed to either a *bufio.Reader
or a local interface type interface { io.Reader; Peek(n int) ([]byte, error) }
and do the appropriate check during construction of the bit reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the complexity of this, I think you'd be better taking the code in bzip2 and adding a PeekBits. That is a trivial addition, using essentially the same code that is in ReadBits, but first Peeking the bytes to need to read the given number of bits. That would be (untested):
func (br *bitReader) PeekBits64(bits uint) (n uint64) { byt, err := br.r.Peek(int(n+7) / 8) if err != nil { if err == io.EOF { err = io.ErrUnexpectedEOF } br.err = err return 0 } for i := 0; bits > br.bits; i++ { b := byt[i] if err != nil { br.err = err return 0 } br.n <<= 8 br.n |= uint64(b) br.bits += 8 } n = (br.n >> (br.bits - bits)) & ((1 << bits) - 1) br.bits -= bits return }
This requires that the copied version of bit_reader.go has the
io.ByteReader
field changed to either a*bufio.Reader
or a local interface typeinterface { io.Reader; Peek(n int) ([]byte, error) }
and do the appropriate check during construction of the bit reader.
Do I need to do any acknowledgement of the original code if I use this ?
The bit_reader.go code is in the standard library. The standard approaches to using third party code apply. |
so I need to put this in the file header: Redistribution and use in source and binary forms, with or without
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ?? |
…pkg, also wrote tests for a series of read and peek operations.
Saxon Nelson-Milton <saxon@ausocean.org>, The Australian Ocean Laboratory (AusOcean) | ||
|
||
LICENSE | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This license only applies to portions (admittedly major portions). You should also include whatever license we are applying to this.
Say which file it was derived from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say which file the code was derived from ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you really use two licenses on the same file ? What if conditions in the licenses clash ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the licenses clash, you can't use them together. That's not limited to file scope. Everything that uses the standard library (i.e. all Go code since runtime is in the standard library) uses the Go license. This just makes it explicit that this code is from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the copyright work ? Do I add the ausocean copyright too ?
I would have abandoned this and started a new PR, but it is what it is. Please squash when you merge. |
…Bits to got []uint64
…bits to get in ReadBits and PeekBits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please squash when you merge.
This is working towards resolving issue #30.