Skip to content

Commit a6646d0

Browse files
committed
pass through error value from de265_image::alloc_image(). #330
1 parent 0a62e71 commit a6646d0

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

libde265/decctx.cc

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,8 +1425,9 @@ int decoder_context::generate_unavailable_reference_picture(const seq_parameter_
14251425
std::shared_ptr<const seq_parameter_set> current_sps = this->sps[ (int)current_pps->seq_parameter_set_id ];
14261426

14271427
int idx = dpb.new_image(current_sps, this, 0,0, false);
1428-
assert(idx>=0);
1429-
//printf("-> fill with unavailable POC %d\n",POC);
1428+
if (idx<0) {
1429+
return idx;
1430+
}
14301431

14311432
de265_image* img = dpb.get_image(idx);
14321433

@@ -1450,7 +1451,7 @@ int decoder_context::generate_unavailable_reference_picture(const seq_parameter_
14501451
14511452
This function will mark pictures in the DPB as 'unused' or 'used for long-term reference'
14521453
*/
1453-
void decoder_context::process_reference_picture_set(slice_segment_header* hdr)
1454+
de265_error decoder_context::process_reference_picture_set(slice_segment_header* hdr)
14541455
{
14551456
std::vector<int> removeReferencesList;
14561457

@@ -1598,6 +1599,9 @@ void decoder_context::process_reference_picture_set(slice_segment_header* hdr)
15981599
// We do not know the correct MSB
15991600
int concealedPicture = generate_unavailable_reference_picture(current_sps.get(),
16001601
PocLtCurr[i], true);
1602+
if (concealedPicture<0) {
1603+
return (de265_error)(-concealedPicture);
1604+
}
16011605
picInAnyList.resize(dpb.size(), false); // adjust size of array to hold new picture
16021606

16031607
RefPicSetLtCurr[i] = k = concealedPicture;
@@ -1624,6 +1628,9 @@ void decoder_context::process_reference_picture_set(slice_segment_header* hdr)
16241628
else {
16251629
int concealedPicture = k = generate_unavailable_reference_picture(current_sps.get(),
16261630
PocLtFoll[i], true);
1631+
if (concealedPicture<0) {
1632+
return (de265_error)(-concealedPicture);
1633+
}
16271634
picInAnyList.resize(dpb.size(), false); // adjust size of array to hold new picture
16281635

16291636
RefPicSetLtFoll[i] = concealedPicture;
@@ -1655,6 +1662,9 @@ void decoder_context::process_reference_picture_set(slice_segment_header* hdr)
16551662
else {
16561663
int concealedPicture = generate_unavailable_reference_picture(current_sps.get(),
16571664
PocStCurrBefore[i], false);
1665+
if (concealedPicture<0) {
1666+
return (de265_error)(-concealedPicture);
1667+
}
16581668
RefPicSetStCurrBefore[i] = k = concealedPicture;
16591669

16601670
picInAnyList.resize(dpb.size(), false); // adjust size of array to hold new picture
@@ -1678,6 +1688,9 @@ void decoder_context::process_reference_picture_set(slice_segment_header* hdr)
16781688
else {
16791689
int concealedPicture = generate_unavailable_reference_picture(current_sps.get(),
16801690
PocStCurrAfter[i], false);
1691+
if (concealedPicture<0) {
1692+
return (de265_error)(-concealedPicture);
1693+
}
16811694
RefPicSetStCurrAfter[i] = k = concealedPicture;
16821695

16831696

@@ -1721,6 +1734,8 @@ void decoder_context::process_reference_picture_set(slice_segment_header* hdr)
17211734
hdr->RemoveReferencesList = removeReferencesList;
17221735

17231736
//remove_images_from_dpb(hdr->RemoveReferencesList);
1737+
1738+
return DE265_OK;
17241739
}
17251740

17261741

@@ -2019,8 +2034,8 @@ bool decoder_context::process_slice_segment_header(slice_segment_header* hdr,
20192034
int image_buffer_idx;
20202035
bool isOutputImage = (!sps->sample_adaptive_offset_enabled_flag || param_disable_sao);
20212036
image_buffer_idx = dpb.new_image(current_sps, this, pts, user_data, isOutputImage);
2022-
if (image_buffer_idx == -1) {
2023-
*err = DE265_ERROR_IMAGE_BUFFER_FULL;
2037+
if (image_buffer_idx < 0) {
2038+
*err = (de265_error)(-image_buffer_idx);
20242039
return false;
20252040
}
20262041

@@ -2072,7 +2087,8 @@ bool decoder_context::process_slice_segment_header(slice_segment_header* hdr,
20722087
// mark picture so that it is not overwritten by unavailable reference frames
20732088
img->PicState = UsedForShortTermReference;
20742089

2075-
process_reference_picture_set(hdr);
2090+
*err = process_reference_picture_set(hdr);
2091+
return false;
20762092
}
20772093

20782094
img->PicState = UsedForShortTermReference;

libde265/decctx.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,14 @@ class decoder_context : public base_context {
513513
int progress);
514514

515515
void process_picture_order_count(slice_segment_header* hdr);
516+
517+
/*
518+
If there is no space for a new image, returns the negative value of an de265_error.
519+
I.e. you can check for error by return_value<0, which is error (-return_value);
520+
*/
516521
int generate_unavailable_reference_picture(const seq_parameter_set* sps,
517522
int POC, bool longTerm);
518-
void process_reference_picture_set(slice_segment_header* hdr);
523+
de265_error process_reference_picture_set(slice_segment_header* hdr);
519524
bool construct_reference_picture_lists(slice_segment_header* hdr);
520525

521526

libde265/dpb.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int decoded_picture_buffer::new_image(std::shared_ptr<const seq_parameter_set> s
210210

211211
// --- search for a free slot in the DPB ---
212212

213-
int free_image_buffer_idx = -1;
213+
int free_image_buffer_idx = -DE265_ERROR_IMAGE_BUFFER_FULL;
214214
for (int i=0;i<dpb.size();i++) {
215215
if (dpb[i]->can_be_released()) {
216216
dpb[i]->release(); /* TODO: this is surely not the best place to free the image, but
@@ -259,7 +259,10 @@ int decoded_picture_buffer::new_image(std::shared_ptr<const seq_parameter_set> s
259259
default: chroma = de265_chroma_420; assert(0); break; // should never happen
260260
}
261261

262-
img->alloc_image(w,h, chroma, sps, true, decctx, /*NULL,*/ pts, user_data, isOutputImage);
262+
de265_error error = img->alloc_image(w,h, chroma, sps, true, decctx, /*NULL,*/ pts, user_data, isOutputImage);
263+
if (error) {
264+
return -error;
265+
}
263266

264267
img->integrity = INTEGRITY_CORRECT;
265268

libde265/dpb.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class decoded_picture_buffer {
3838
void set_norm_size_of_DPB(int n) { norm_images_in_DPB=n; }
3939

4040
/* Alloc a new image in the DPB and return its index.
41-
If there is no space for a new image, return -1. */
41+
If there is no space for a new image, returns the negative value of an de265_error.
42+
I.e. you can check for error by return_value<0, which is error (-return_value);
43+
*/
4244
int new_image(std::shared_ptr<const seq_parameter_set> sps, decoder_context* decctx,
4345
de265_PTS pts, void* user_data, bool isOutputImage);
4446

0 commit comments

Comments
 (0)