libmp3splt
src/sync_errors.c
Go to the documentation of this file.
00001 /**********************************************************
00002  *
00003  * libmp3splt -- library based on mp3splt,
00004  *               for mp3/ogg splitting without decoding
00005  *
00006  * Copyright (c) 2002-2005 M. Trotta - <mtrotta@users.sourceforge.net>
00007  * Copyright (c) 2005-2011 Alexandru Munteanu - io_fx@yahoo.fr
00008  *
00009  * http://mp3splt.sourceforge.net
00010  *
00011  *********************************************************/
00012 
00013 /**********************************************************
00014  *
00015  * This program is free software; you can redistribute it and/or
00016  * modify it under the terms of the GNU General Public License
00017  * as published by the Free Software Foundation; either version 2
00018  * of the License, or (at your option) any later version.
00019  *
00020  * This program is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License
00026  * along with this program; if not, write to the Free Software
00027  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00028  * 02111-1307,
00029  * USA.
00030  *
00031  *********************************************************/
00032 
00048 #include "splt.h"
00049 
00050 void splt_se_set_sync_errors_default_values(splt_state *state)
00051 {
00052   splt_syncerrors *serrors = state->serrors;
00053 
00054   state->syncerrors = 0;
00055   serrors->serrors_points = NULL;
00056   serrors->serrors_points_num = 0;
00057 }
00058 
00059 int splt_se_serrors_append_point(splt_state *state, off_t point)
00060 {
00061   int error = SPLT_OK;
00062 
00063   splt_syncerrors *serrors = state->serrors;
00064 
00065   int serrors_num = serrors->serrors_points_num;
00066 
00067   serrors->serrors_points_num++;
00068 
00069   if (point >= 0)
00070   {
00071     if (serrors->serrors_points == NULL)
00072     {
00073       if((serrors->serrors_points = 
00074             malloc(sizeof(off_t) * (serrors_num + 1))) == NULL)
00075       {
00076         error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00077       }
00078       else
00079       {
00080         serrors->serrors_points[0] = 0;
00081       }
00082     }
00083     else
00084     {
00085       if((serrors->serrors_points = realloc(serrors->serrors_points,
00086               sizeof(off_t) * (serrors_num + 1))) == NULL)
00087       {
00088         error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00089       }
00090     }
00091 
00092     if (error == SPLT_OK)
00093     {
00094       serrors->serrors_points[serrors_num] = point;
00095 
00096       if (point == -1)
00097       {
00098         error = SPLT_ERR_SYNC;
00099       }
00100     }
00101   }
00102   else
00103   {
00104     splt_e_error(SPLT_IERROR_INT, __func__, point, NULL);
00105   }
00106 
00107   return error;
00108 }
00109 
00110 void splt_se_serrors_free(splt_state *state)
00111 {
00112   splt_syncerrors *serrors = state->serrors;
00113 
00114   if (!serrors)
00115   {
00116     return;
00117   }
00118 
00119   if (serrors->serrors_points)
00120   {
00121     free(serrors->serrors_points);
00122     serrors->serrors_points = NULL;
00123     serrors->serrors_points_num = 0;
00124   }
00125 }
00126