1 /*
2  * Datastructures for filtering ES data ("fast forward") and writing to ES or
3  * TS.
4  *
5  * ***** BEGIN LICENSE BLOCK *****
6  * Version: MPL 1.1
7  *
8  * The contents of this file are subject to the Mozilla Public License Version
9  * 1.1 (the "License"); you may not use this file except in compliance with
10  * the License. You may obtain a copy of the License at
11  * http://www.mozilla.org/MPL/
12  *
13  * Software distributed under the License is distributed on an "AS IS" basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15  * for the specific language governing rights and limitations under the
16  * License.
17  *
18  * The Original Code is the MPEG TS, PS and ES tools.
19  *
20  * The Initial Developer of the Original Code is Amino Communications Ltd.
21  * Portions created by the Initial Developer are Copyright (C) 2008
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *   Amino Communications Ltd, Swavesey, Cambridge UK
26  *
27  * ***** END LICENSE BLOCK *****
28  */
29 
30 #ifndef _filter_defns
31 #define _filter_defns
32 
33 #include "compat.h"
34 #include "es_defns.h"
35 #include "h262_defns.h"
36 #include "accessunit_defns.h"
37 #include "reverse_defns.h"
38 
39 // Filtering comes in two varieties:
40 // - "stripping" means retaining just reference pictures. For H.262 this
41 //   means the I pictures (and maybe the P pictures), for H.264 this means
42 //   the IDR and I pictures (or maybe all reference pictures). This is simple
43 //   to do, but the speedup resulting is very dependant on the data.
44 // - "filtering" means attempting to keep frames as a particular frequency,
45 //   so, for instance, a frequency of 8 would mean trying to keep every 8th
46 //   frame, or a speedup of 8x. This is harder to do as it depends rather
47 //   crucially on the distribution of reference frames in the data.
48 
49 // ------------------------------------------------------------
50 struct h262_filter_context
51 {
52   h262_context_p  h262; // The H.262 stream we are reading from
53   int   filter;  // TRUE if filtering, FALSE if stripping
54   int   freq;    // Frequency of frames to try to keep if filtering
55   int   allref;  // Keep all I and P pictures if stripping?
56   // (the name `allref` is used for compatibility with the H.264 filter
57   // context - it's a little easier to have one name for both filters)
58 
59   // For any operation on H.262, we want:
60   int   pending_EOF;  // next time a function is called, say we had EOF
61 
62   // When filtering, we want:
63   int   count;    // a rolling count to compare with the desired frequency
64   int   last_was_slice;
65   int   had_previous_picture;
66   h262_picture_p  last_seq_hdr;
67 
68   // When stripping, we want:
69   int   new_seq_hdr;    // has the sequence header changed?
70 
71   int   frames_seen;    // number of pictures seen this filter run
72   int   frames_written; // number of pictures written (or, returned)
73 };
74 typedef struct h262_filter_context *h262_filter_context_p;
75 #define SIZEOF_H262_FILTER_CONTEXT sizeof(struct h262_filter_context)
76 
77 // ------------------------------------------------------------
78 struct h264_filter_context
79 {
80   access_unit_context_p  access_unit_context;  // our "reader" for access units
81   int   filter;  // TRUE if filtering, FALSE if stripping
82   int   freq;    // Frequency of frames to try to keep if filtering
83   int   allref;  // Keep all reference pictures
84 
85   // When filtering, we want:
86   // a rolling count to compare with the desired frequency
87   int   count;
88   // `skipped_ref_pic` is TRUE if we've skipped any reference pictures
89   // since our last IDR.
90   int  skipped_ref_pic;
91   // `last_accepted_was_not_IDR` is TRUE if the last frame kept (output)
92   // was not an IDR. We set it TRUE initially so that we will decide
93   // to output the first IDR we *do* find, regardless of the count.
94   int  last_accepted_was_not_IDR;
95   int  had_previous_access_unit;
96 
97   // Have we had an IDR in this run of the filter?
98   int  not_had_IDR;
99 
100   int  frames_seen;    // number seen this filter run
101   int  frames_written; // number written (or, returned)
102 };
103 typedef struct h264_filter_context *h264_filter_context_p;
104 #define SIZEOF_H264_FILTER_CONTEXT sizeof(struct h264_filter_context)
105 
106 #endif // _filter_defns
107 
108 // Local Variables:
109 // tab-width: 8
110 // indent-tabs-mode: nil
111 // c-basic-offset: 2
112 // End:
113 // vim: set tabstop=8 shiftwidth=2 expandtab:
114