File: overlap.h

package info (click to toggle)
vdr-plugin-markad 4.2.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,084 kB
  • sloc: cpp: 22,441; python: 613; makefile: 270; sh: 95
file content (141 lines) | stat: -rw-r--r-- 4,329 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * overlap.h: A program for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 */

#ifndef __overlap_h_
#define __overlap_h_

#include "tools.h"
#include "marks.h"
#include "decoder.h"




/**
 * class to detect overlapping scenes before and after a single advertising
 */
class cOverlapAroundAd {
public:

    /**
     * constructor of overlap detection
     * @param decoderParam pointer to decoder
     */
    explicit cOverlapAroundAd(cDecoder *decoderParam);

    ~cOverlapAroundAd();

/// process overlap detection
    /**
     * if beforeAd == true preload frames before stop mark in histogram buffer array, otherwise preload frames after start mark <br>
     * if we got frameCount, start compare
     * @param[in]     picture      video picture
     * @param[in]     frameCount   number of frames to process
     * @param[in]     beforeAd     true if called with a frame before advertising, false otherwise
     * @param[in]     h264         true if HD video, false otherwise
     */
    void Process(const sVideoPicture *picture, const int frameCount, const bool beforeAd, const bool h264);

    /**
     * detect overlaps before and after advertising
     * @param[in,out] overlapPos new stop and start mark pair after overlap detection, -1 if no overlap was found
     */
    void Detect(sOverlapPos *overlapPos);

private:

    enum {
        OV_BEFORE = 0,
        OV_AFTER  = 1
    };

    typedef int simpleHistogram[256];     //!< histogram array
    //!<

    /**
     * check if two histogram are similar
     * @param hist1 histogram 1
     * @param hist2 histogram 2
     * @return different pixels if similar, <0 otherwise
     */
    int AreSimilar(const simpleHistogram &hist1, const simpleHistogram &hist2) const;

    /**
     * get a simple histogram of current frame
     * @param[in]     picture    video picture
     * @param[in,out] dest       histogram
     */
    void GetHistogram(const sVideoPicture *picture, simpleHistogram &dest) const;

    /**
     * histogram buffer for overlap detection
     */
    typedef struct sHistBuffer {
        int frameNumber = -1;      //!< frame number
        //!<
        int64_t pts     = -1;      //!< pts of picture
        //!<
        bool valid      = false;   //!< true if buffer is valid
        //!<
        simpleHistogram histogram; //!< simple frame histogram
        //!<
    } sHistBuffer;

    cDecoder *decoder         = nullptr;    //!< pointer to decoder
    //!<
    sHistBuffer *histbuf[2]   = {nullptr};  //!< simple frame histogram with frame number
    //!<
    int histcnt[2]            = {0};        //!< count of prcessed frame histograms
    //!<
    int histframes[2]         = {0};        //!< frame number of histogram buffer content
    //!<
    int lastFrameNumber       = 0;          //!< last processed frame number
    //!<
    int similarCutOff         = 0;          //!< maximum different pixel to treat picture as similar, depends on resolution
    //!<
    int similarMinLength      = 0;          //!< minimum similar frames for a overlap
    //!<
};


/**
 * class to detect overlapping scenes and closing credits in recording
 */
class cOverlap : private cTools {
public:
    /**
     * process overlap detection with all ads
     * @param  decoderParam  pointer to decoder
     * @param  indexParam    pointer to index
     */
    cOverlap(cDecoder *decoderParam, cIndex *indexParam);
    ~cOverlap();

    /**
     * detect overlap
     * @param marksParam      current marks
     */
    bool DetectOverlap(cMarks *marksParam);

    /**
     * process overlap detection with stop/start pair
     * @param[in]      overlapAroundAd detection object
     * @param[in, out] mark1           stop mark before advertising, set to start position of detected overlap
     * @param[in, out] mark2           start mark after advertising, set to end position of detected overlap
     * @return true if overlap was detected, false otherwise
     */
    bool ProcessMarksOverlap(cOverlapAroundAd *overlapAroundAd, cMark **mark1, cMark **mark2);

private:
    cDecoder *decoder         = nullptr;   //!< decoder
    //!<
    cIndex   *index           = nullptr;   //!< recording index
    //!<
    cMarks   *marks           = nullptr;   //!< marks
    //!<
};
#endif