mirror of
				https://github.com/aler9/gortsplib
				synced 2025-10-31 02:26:57 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			47 lines
		
	
	
		
			964 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			964 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package rtpmjpeg
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| )
 | |
| 
 | |
| type headerQuantizationTable struct {
 | |
| 	MBZ       uint8
 | |
| 	Precision uint8
 | |
| 	Tables    []byte
 | |
| }
 | |
| 
 | |
| func (h *headerQuantizationTable) unmarshal(byts []byte) (int, error) {
 | |
| 	if len(byts) < 4 {
 | |
| 		return 0, fmt.Errorf("buffer is too short")
 | |
| 	}
 | |
| 
 | |
| 	h.MBZ = byts[0]
 | |
| 	h.Precision = byts[1]
 | |
| 	if h.Precision != 0 {
 | |
| 		return 0, fmt.Errorf("Precision %d is not supported", h.Precision)
 | |
| 	}
 | |
| 
 | |
| 	length := int(byts[2])<<8 | int(byts[3])
 | |
| 	switch length {
 | |
| 	case 64, 128:
 | |
| 	default:
 | |
| 		return 0, fmt.Errorf("Quantization table length %d is not supported", length)
 | |
| 	}
 | |
| 
 | |
| 	if (len(byts) - 4) < length {
 | |
| 		return 0, fmt.Errorf("buffer is too short")
 | |
| 	}
 | |
| 
 | |
| 	h.Tables = byts[4 : 4+length]
 | |
| 	return 4 + length, nil
 | |
| }
 | |
| 
 | |
| func (h headerQuantizationTable) marshal(byts []byte) []byte {
 | |
| 	byts = append(byts, h.MBZ)
 | |
| 	byts = append(byts, h.Precision)
 | |
| 	l := len(h.Tables)
 | |
| 	byts = append(byts, []byte{byte(l >> 8), byte(l)}...)
 | |
| 	byts = append(byts, h.Tables...)
 | |
| 	return byts
 | |
| }
 | 
