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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>get_next_access_unit.py.html</title>
<meta name="Generator" content="Vim/7.1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#e5e5e5" text="#000000"><font face="monospace">
<font color="#0000ff"># Pseudo-Python rendition of the code for ``get_next_access_unit()``.</font><br>
<br>
<font color="#0000ff"># ***** BEGIN LICENSE BLOCK *****</font><br>
<font color="#0000ff"># Version: MPL 1.1</font><br>
<font color="#0000ff"># </font><br>
<font color="#0000ff"># The contents of this file are subject to the Mozilla Public License Version</font><br>
<font color="#0000ff"># 1.1 (the "License"); you may not use this file except in compliance with</font><br>
<font color="#0000ff"># the License. You may obtain a copy of the License at</font><br>
<font color="#0000ff"># <a href="http://www.mozilla.org/MPL/">http://www.mozilla.org/MPL/</a></font><br>
<font color="#0000ff"># </font><br>
<font color="#0000ff"># Software distributed under the License is distributed on an "AS IS" basis,</font><br>
<font color="#0000ff"># WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License</font><br>
<font color="#0000ff"># for the specific language governing rights and limitations under the</font><br>
<font color="#0000ff"># License.</font><br>
<font color="#0000ff"># </font><br>
<font color="#0000ff"># The Original Code is the MPEG TS, PS and ES tools.</font><br>
<font color="#0000ff"># </font><br>
<font color="#0000ff"># The Initial Developer of the Original Code is Amino Communications Ltd.</font><br>
<font color="#0000ff"># Portions created by the Initial Developer are Copyright (C) 2008</font><br>
<font color="#0000ff"># the Initial Developer. All Rights Reserved.</font><br>
<font color="#0000ff"># </font><br>
<font color="#0000ff"># Contributor(s):</font><br>
<font color="#0000ff"># Amino Communications Ltd, Swavesey, Cambridge UK</font><br>
<font color="#0000ff"># </font><br>
<font color="#0000ff"># ***** END LICENSE BLOCK *****</font><br>
<br>
<font color="#a52a2a"><b>def</b></font> <font color="#008b8b">get_next_access_unit</font>(context):<br>
<span style="background-color: #f2f2f2"><font color="#ff00ff">"""Retrieve the next access unit from the file described by `context`.</font></span><br>
<span style="background-color: #f2f2f2"><font color="#ff00ff"> """</font></span><br>
access_unit = build_access_unit()<br>
<font color="#a52a2a"><b>if</b></font> context.pending_nal: <font color="#0000ff"># i.e., we already had a NAL to start this unit</font><br>
access_unit.append(context.pending_nal,TRUE,context.pending_list)<br>
context.pending_nal = NULL<br>
context.pending_list.reset(FALSE)<br>
<br>
<font color="#a52a2a"><b>while</b></font> <span style="background-color: #f2f2f2"><font color="#ff00ff">1</font></span>:<br>
<font color="#a52a2a"><b>try</b></font>:<br>
nal = context.find_next_NAL_unit()<br>
<font color="#a52a2a"><b>except</b></font> EOF:<br>
context.no_more_data = TRUE; <font color="#0000ff"># prevent future reads on this stream</font><br>
<font color="#a52a2a"><b>break</b></font><br>
<font color="#a52a2a"><b>except</b></font> BrokenNALUnit:<br>
WARNING(<span style="background-color: #f2f2f2"><font color="#ff00ff">"!!! Ignoring broken NAL unit</font></span><span style="background-color: #f2f2f2"><font color="#6a5acd">\n</font></span><span style="background-color: #f2f2f2"><font color="#ff00ff">"</font></span>)<br>
access_unit.ignored_broken_NAL_units += <span style="background-color: #f2f2f2"><font color="#ff00ff">1</font></span><br>
<font color="#a52a2a"><b>continue</b></font><br>
<br>
<font color="#a52a2a"><b>if</b></font> nal.is_slice():<br>
<font color="#a52a2a"><b>if</b></font> <font color="#a52a2a"><b>not</b></font> access_unit.started_primary_picture:<br>
<font color="#0000ff"># We're in a new access unit, but we haven't had a slice</font><br>
<font color="#0000ff"># yet, so we can be lazy and assume that this must be the</font><br>
<font color="#0000ff"># first slice</font><br>
nal.start_reason = <span style="background-color: #f2f2f2"><font color="#ff00ff">"First slice of new access unit"</font></span><br>
access_unit.append(nal,TRUE,context.pending_list)<br>
context.pending_list.reset(FALSE)<br>
context.remember_earlier_primary_start(nal)<br>
<font color="#a52a2a"><b>elif</b></font> nal.is_first_VCL_NAL(context.earlier_primary_start):<br>
<font color="#0000ff"># Regardless of what we determine next, we need to remember</font><br>
<font color="#0000ff"># that the NAL started (what may later be the previous) access</font><br>
<font color="#0000ff"># unit</font><br>
context.remember_earlier_primary_start(nal)<br>
<font color="#a52a2a"><b>if</b></font> access_unit.started_primary_picture:<br>
<font color="#0000ff"># We were already in an access unit with a primary</font><br>
<font color="#0000ff"># picture, so this NAL unit must start a new access unit.</font><br>
<font color="#0000ff"># Remember it for next time, and return the access unit so</font><br>
<font color="#0000ff"># far.</font><br>
context.pending_nal = nal<br>
<font color="#a52a2a"><b>break</b></font>; <font color="#0000ff"># Ready to return the access unit</font><br>
<font color="#a52a2a"><b>else</b></font>:<br>
<font color="#0000ff"># This access unit was waiting for its primary picture</font><br>
access_unit.append(nal,TRUE,context.pending_list)<br>
context.pending_list.reset(FALSE)<br>
<font color="#a52a2a"><b>elif</b></font> <font color="#a52a2a"><b>not</b></font> access_unit.started_primary_picture:<br>
<font color="#0000ff"># But this is not a NAL unit that may start a new</font><br>
<font color="#0000ff"># access unit. So what should we do? Ignore it?</font><br>
<font color="#a52a2a"><b>if</b></font> <font color="#a52a2a"><b>not</b></font> quiet:<br>
WARNING(<span style="background-color: #f2f2f2"><font color="#ff00ff">"!!! Ignoring VCL NAL that cannot start a new"</font></span><br>
<span style="background-color: #f2f2f2"><font color="#ff00ff">" primary picture: "</font></span><br>
nal.report(stderr)<br>
<font color="#a52a2a"><b>elif</b></font> nal_is_redundant(nal):<br>
<font color="#0000ff"># printf(" ignoring redundant NAL unit\n")</font><br>
<font color="#a52a2a"><b>pass</b></font><br>
<font color="#a52a2a"><b>else</b></font>:<br>
<font color="#0000ff"># We're part of the same access unit, but not special</font><br>
access_unit.append(nal,FALSE,context.pending_list)<br>
context.pending_list.reset(FALSE)<br>
<font color="#a52a2a"><b>elif</b></font> nal.nal_unit_type == NAL_ACCESS_UNIT_DELIM:<br>
<font color="#0000ff"># An access unit delimiter always starts a new access unit</font><br>
<font color="#a52a2a"><b>if</b></font> access_unit.started_primary_picture:<br>
context.pending_list.append(nal)<br>
<font color="#a52a2a"><b>break</b></font> <font color="#0000ff"># Ready to return the "previous" access unit</font><br>
<font color="#a52a2a"><b>else</b></font>:<br>
<font color="#0000ff"># The current access unit doesn't yet have any VCL NALs</font><br>
<font color="#a52a2a"><b>if</b></font> context.pending_list.length > <span style="background-color: #f2f2f2"><font color="#ff00ff">0</font></span>:<br>
WARNING(<span style="background-color: #f2f2f2"><font color="#ff00ff">"!!! Ignoring items after last VCL NAL and"</font></span><br>
<span style="background-color: #f2f2f2"><font color="#ff00ff">" before Access Unit Delimiter</font></span><span style="background-color: #f2f2f2"><font color="#6a5acd">\n</font></span><span style="background-color: #f2f2f2"><font color="#ff00ff">"</font></span>)<br>
context.pending_list.report(stderr,<span style="background-color: #f2f2f2"><font color="#ff00ff">" "</font></span>,NULL,)<br>
context.pending_list.reset(TRUE)<br>
<font color="#a52a2a"><b>if</b></font> access_unit.nal_units.length > <span style="background-color: #f2f2f2"><font color="#ff00ff">0</font></span>:<br>
WARNING(<span style="background-color: #f2f2f2"><font color="#ff00ff">"!!! Ignoring incomplete access unit</font></span><span style="background-color: #f2f2f2"><font color="#6a5acd">\n</font></span><span style="background-color: #f2f2f2"><font color="#ff00ff">"</font></span>)<br>
access_unit.nal_units.report(stderr,<span style="background-color: #f2f2f2"><font color="#ff00ff">" "</font></span>,NULL,)<br>
access_unit.nal_units.reset(TRUE)<br>
access_unit.append(nal,FALSE,NULL)<br>
<font color="#a52a2a"><b>elif</b></font> nal.nal_unit_type == NAL_SEI:<br>
<font color="#0000ff"># SEI units always precede the primary coded picture</font><br>
<font color="#0000ff"># - so they also implicitly end any access unit that has already</font><br>
<font color="#0000ff"># started its primary picture</font><br>
<font color="#a52a2a"><b>if</b></font> access_unit.started_primary_picture:<br>
context.pending_list.append(nal)<br>
<font color="#a52a2a"><b>break</b></font> <font color="#0000ff"># Ready to return the "previous" access unit</font><br>
<font color="#a52a2a"><b>else</b></font>:<br>
context.pending_list.append(nal)<br>
<font color="#a52a2a"><b>elif</b></font> nal.nal_unit_type <font color="#a52a2a"><b>in</b></font> [NAL_SEQ_PARAM_SET, NAL_PIC_PARAM_SET,<br>
<span style="background-color: #f2f2f2"><font color="#ff00ff">13</font></span>, <span style="background-color: #f2f2f2"><font color="#ff00ff">14</font></span>, <span style="background-color: #f2f2f2"><font color="#ff00ff">15</font></span>, <span style="background-color: #f2f2f2"><font color="#ff00ff">16</font></span>, <span style="background-color: #f2f2f2"><font color="#ff00ff">17</font></span>, <span style="background-color: #f2f2f2"><font color="#ff00ff">18</font></span>]:<br>
<font color="#0000ff"># These start a new access unit *if* they come after the last VCL</font><br>
<font color="#0000ff"># NAL of an access unit. But we can only *tell* that they are</font><br>
<font color="#0000ff"># after the last VCL NAL of an access unit when we start the next</font><br>
<font color="#0000ff"># access unit - so we need to hold them in hand until we know that</font><br>
<font color="#0000ff"># we need them. (i.e., they'll get added to an access unit just</font><br>
<font color="#0000ff"># before the next "more determined" NAL unit we add to an access</font><br>
<font color="#0000ff"># unit)</font><br>
context.pending_list.append(nal)<br>
<font color="#a52a2a"><b>elif</b></font> nal.nal_unit_type == NAL_END_OF_SEQ:<br>
<font color="#a52a2a"><b>if</b></font> context.pending_list.length > <span style="background-color: #f2f2f2"><font color="#ff00ff">0</font></span>:<br>
WARNING(<span style="background-color: #f2f2f2"><font color="#ff00ff">"!!! Ignoring items after last VCL NAL and"</font></span><br>
<span style="background-color: #f2f2f2"><font color="#ff00ff">" before End of Sequence</font></span><span style="background-color: #f2f2f2"><font color="#6a5acd">\n</font></span><span style="background-color: #f2f2f2"><font color="#ff00ff">"</font></span>)<br>
context.pending_list.report(stderr,<span style="background-color: #f2f2f2"><font color="#ff00ff">" "</font></span>,NULL,)<br>
context.pending_list.reset(TRUE)<br>
<font color="#0000ff"># And remember this as the End of Sequence marker</font><br>
context.end_of_sequence = nal<br>
<font color="#a52a2a"><b>break</b></font><br>
<font color="#a52a2a"><b>elif</b></font> nal.nal_unit_type == NAL_END_OF_STREAM:<br>
<font color="#0000ff"># And remember this as the End of Stream marker</font><br>
context.end_of_stream = nal<br>
<font color="#0000ff"># Which means there's no point in reading more from this stream</font><br>
<font color="#0000ff"># (setting no_more_data like this means that *next* time this</font><br>
<font color="#0000ff"># function is called, it will return EOF)</font><br>
context.no_more_data = TRUE<br>
<font color="#0000ff"># And we're done</font><br>
<font color="#a52a2a"><b>break</b></font><br>
<font color="#a52a2a"><b>else</b></font>:<br>
<font color="#0000ff"># It's not a slice, or an access unit delimiter, or an</font><br>
<font color="#0000ff"># end of sequence or stream, or a sequence or picture</font><br>
<font color="#0000ff"># parameter set, or various other odds and ends, so it</font><br>
<font color="#0000ff"># looks like we can ignore it.</font><br>
<font color="#a52a2a"><b>pass</b></font><br>
<br>
<font color="#0000ff"># Check for an immediate "end of file with no data"</font><br>
<font color="#0000ff"># - i.e., we read EOF or end of stream, and there was nothing</font><br>
<font color="#0000ff"># between the last access unit and such reading</font><br>
<font color="#a52a2a"><b>if</b></font> context.no_more_data <font color="#a52a2a"><b>and</b></font> access_unit.nal_units.length == <span style="background-color: #f2f2f2"><font color="#ff00ff">0</font></span>:<br>
<font color="#a52a2a"><b>raise</b></font> EOF<br>
<br>
<font color="#0000ff"># Otherwise, finish off and return the access unit we have in hand</font><br>
access_unit.end(context,show_details)<br>
<br>
<font color="#0000ff"># Remember to count it</font><br>
context.access_unit_index += <span style="background-color: #f2f2f2"><font color="#ff00ff">1</font></span><br>
<br>
<font color="#a52a2a"><b>return</b></font> access_unit<br>
</font></body>
</html>
|