codec/h264/decode/mbtype.go: improve MbPartPredMode switch logic

Issue #109 on hold
Saxon Milton created an issue

The function here has some switch logic that could be simplified.

Comments (7)

  1. kortschak

    I would do it this way:

    func MbPartPredMode(data *SliceData, sliceType string, mbType, partition int) (mbPartPredMode, error) {
        if partition != 0 {
            return naMbPartPredMode, errPartition
        }
        switch sliceType {
        case "I":
            if mbType == 0 {
                if data.TransformSize8x8Flag {
                    return intra8x8, nil
                }
                return intra4x4, nil
            }
            if 0 < mbType && mbType < 25 {
                return intra16x16, nil
            }
            return naMbPartPredMode, errNaMode
        case "SI":
            if mbType != 0 {
                return naMbPartPredMode, errNaMode
            }
            return intra4x4, nil
        case "P", "SP":
            switch {
            case 0 <= mbType && mbType < 3:
                return predL0, nil
            case mbType == 3 || mbType == 4:
                return naMbPartPredMode, errNaMode
            default:
                return predL0, nil
            }
        case "B":
            switch mbType {
            case 0:
                return direct, nil
            case 3:
                return biPred, nil
            case 1, 4, 5, 8, 9, 12, 13:
                return predL0, nil
            case 2, 6, 7, 10, 11, 14, 15:
                return predL1, nil
            case 22:
                return naMbPartPredMode, errNaMode
            default:
                if mbType > 15 && mbType < 22 {
                    return biPred, nil
                }
                return direct, nil
            }
        default:
            return naMbPartPredMode, errSliceType
        }
    }
    

    I was just going through the steps to send that as a PR, but that part of the tree is not connected to the client code and the paths look wrong (the path is .../decode, but the package is h264).

  2. Saxon Milton reporter

    @kortschak Yes, it didn’t occur to me I’d have to change the package for every file. I’ll do that now.

  3. kortschak

    It's not just that, the imports still point to the github repo and the go.mod file exists (it shouldn't). The path name terminal should be something more descriptive than "decode".

  4. Log in to comment