int CPPMDecoder_init(decoders_CPPMDecoder *self, PyObject *args, PyObject *kwds) { #ifdef HAS_UNPROT char *mkb_file; char *dvda_device; self->decoder.media_type = 0; self->decoder.media_key = 0; self->decoder.id_album_media = 0; if (!PyArg_ParseTuple(args, "ss", &dvda_device, &mkb_file)) return -1; /*initialize the decoder from the device path and mkb_file path*/ switch (cppm_init(&(self->decoder), dvda_device, mkb_file)) { case -1: /*I/O error*/ PyErr_SetFromErrno(PyExc_IOError); return -1; case -2: /*unsupported protection type*/ PyErr_SetString(PyExc_ValueError, "unsupported protection type"); return -1; default: /*all okay*/ break; } #endif return 0; }
static DVDA_Sector_Reader* open_sector_reader(const char* audio_ts_path, unsigned titleset_number, const char* cdrom_device) { DVDA_Sector_Reader* reader = malloc(sizeof(DVDA_Sector_Reader)); unsigned i; reader->aobs = a_obj_new(NULL, (ARRAY_FREE_FUNC)free_aob, NULL); #ifdef HAS_UNPROT reader->cppm_decoder = NULL; #endif for (i = 1; i <= 9; i++) { char aob[13]; char* path; snprintf(aob, 13, "ATS_%2.2d_%d.AOB", titleset_number, i); if ((path = find_audio_ts_file(audio_ts_path, aob)) != NULL) { struct stat aob_stat; if (!stat(path, &aob_stat)) { DVDA_AOB* aob = malloc(sizeof(DVDA_AOB)); aob->path = path; if ((aob->file = fopen(aob->path, "rb")) == NULL) { /*error opening AOB for reading*/ free(aob); close_sector_reader(reader); return NULL; } aob->total_sectors = (unsigned)(aob_stat.st_size / SECTOR_SIZE); /*set AOBs first_sector and last_sector relative to the previous AOB, if any*/ if (reader->aobs->len) { DVDA_AOB* last_aob = reader->aobs->_[reader->aobs->len - 1]; aob->start_sector = last_aob->end_sector + 1; } else { aob->start_sector = 0; } aob->end_sector = aob->start_sector + (aob->total_sectors - 1); reader->end_sector = aob->end_sector; reader->aobs->append(reader->aobs, aob); } else { /*error getting stat of AOB, free memory and return error*/ close_sector_reader(reader); return NULL; } } else { /*AOB not found, so exit loop*/ break; } } if (reader->aobs->len) { /*ran out of AOBs, set initial position to start of 0th sector*/ reader->current.sector = 0; reader->current.aob = reader->aobs->_[0]; #ifdef HAS_UNPROT /*if cdrom device given, initialize CPPM decoder if possible*/ if (cdrom_device != NULL) { char* dvdaudio_mkb = find_audio_ts_file(audio_ts_path, "DVDAUDIO.MKB"); if (dvdaudio_mkb != NULL) { reader->cppm_decoder = malloc(sizeof(struct cppm_decoder)); reader->cppm_decoder->media_type = 0; reader->cppm_decoder->media_key = 0; reader->cppm_decoder->id_album_media = 0; switch (cppm_init(reader->cppm_decoder, cdrom_device, dvdaudio_mkb)) { case -1: /* I/O error */ free(dvdaudio_mkb); close_sector_reader(reader); return NULL; case -2: /* unsupported protection type */ free(dvdaudio_mkb); close_sector_reader(reader); fprintf(stderr, "unsupported protection type\n"); errno = ENOENT; return NULL; default: /* all okay */ free(dvdaudio_mkb); break; } } } #endif return reader; } else { /*couldn't find any matching AOB files for titleset*/ close_sector_reader(reader); errno = ENOENT; return NULL; } }