int32 GoGoEncoder::WriteDetails(BMessage* message) { PRINT(("GoGoEncoder::WriteDetails(BMessage*)\n")); const char* outputFile; const char* artist; const char* album; const char* title; const char* year; const char* comment; const char* track; const char* genre; if (message->FindString("output file", &outputFile) != B_OK) { return B_ERROR; } message->FindString("artist", &artist); message->FindString("album", &album); message->FindString("title", &title); message->FindString("year", &year); message->FindString("comment", &comment); message->FindString("track", &track); message->FindString("genre", &genre); dev_t device = dev_for_path(outputFile); BVolume volume(device); if (volume.InitCheck() != B_OK) { return B_ERROR; } BFile mp3File(outputFile, B_READ_WRITE); if (mp3File.InitCheck() != B_OK) { return B_ERROR; } if (volume.KnowsMime()) { BNodeInfo info(&mp3File); if (info.InitCheck() != B_OK) { return B_ERROR; } if (info.SetType(MP3_MIME_TYPE) != B_OK) { return B_ERROR; } } if (volume.KnowsAttr()) { AudioAttributes attributes(&mp3File); attributes.SetArtist(artist); attributes.SetAlbum(album); attributes.SetTitle(title); attributes.SetYear(year); attributes.SetComment(comment); attributes.SetTrack(track); attributes.SetGenre(genre); if (attributes.Write() != B_OK) { return B_ERROR; } } ID3Tags tags(outputFile); tags.SetArtist(artist); tags.SetAlbum(album); tags.SetTitle(title); tags.SetYear(year); tags.SetComment(comment); tags.SetTrack(track); tags.SetGenre(genre); if (tags.Write() != B_OK) { return B_ERROR; } return B_OK; }
int internel_decoder::get_attached_images(char* url,stream_context *streamcontext){ stream_context *sc = streamcontext; AVInputFormat *format = sc->pFormatCtx->iformat; if(strcmp(format->name,"mp3") == 0){ sc->is_mp3 = 1; } /// If attached image of mp3 is not detected by ffmpeg then we use taglib to extract the attached image if(strcmp(format->name,"mp3") == 0 && sc->videostream == -1){ TagLib::MPEG::File mp3File(url); Tag * mp3Tag; FrameList listOfMp3Frames; AttachedPictureFrame * pictureFrame; AVPacket packet; //av_init_packet(&packet); mp3Tag= mp3File.ID3v2Tag(); if(mp3Tag) { listOfMp3Frames = mp3Tag->frameListMap()["APIC"]; if(!listOfMp3Frames.isEmpty()) { FrameList::ConstIterator it= listOfMp3Frames.begin(); // for(; it != listOfMp3Frames.end() ; it++) // { pictureFrame = static_cast<AttachedPictureFrame *> (*it); //cout <<"mime-type:"<<pictureFrame->mimeType()<<endl; AVCodec *codec; const char *mime_attached = pictureFrame->mimeType().toCString(false); const CodecMime *mime = ff_id3v2_mime_tags; while (mime->id != AV_CODEC_ID_NONE) { if (!av_strncasecmp(mime->str, mime_attached, sizeof(mime_attached))) { codec = avcodec_find_decoder(mime->id); cout <<"mime-type:"<<mime->str<<endl; break; } mime++; } if(mime->id != AV_CODEC_ID_NONE){ av_new_packet (&packet, pictureFrame->picture().size()); memcpy(packet.data,pictureFrame->picture().data(),pictureFrame->picture().size()); // packet.data = (uint8_t*)pictureFrame->picture().data(); packet.size = pictureFrame->picture().size(); packet.flags = AV_PKT_FLAG_KEY; pthread_mutex_lock(&sc->videolock); sc->videobuffer.push(packet); pthread_mutex_unlock(&sc->videolock); sc->videoctx = avcodec_alloc_context3(NULL); avcodec_open2(sc->videoctx,codec, NULL); sc->attachedimage = 1; AVFrame *frame = avcodec_alloc_frame(); int decode_ok; int len; while(true){ len = avcodec_decode_video2(sc->videoctx, frame, &decode_ok, &packet); if(decode_ok || len < 0){ break; } } if(len < 0){ sc->videoctx->width = 0; sc->videoctx->height = 0; sc->height = 0; sc->width = 0; av_free(frame); return -1; }else{ cout <<frame->height<<" - "<<frame->width<<endl; sc->videoctx->width = frame->width; sc->videoctx->height = frame->height; sc->height = frame->height; sc->width = frame->width; av_free(frame); } }else{ return -1; } //break; // } } else{ return -1; } } else { return -1; } } return 0; }
static PVMFStatus parseMP3(const char *filename,MediaScannerClient& client) { PVID3ParCom pvId3Param; PVFile fileHandle; Oscl_FileServer iFs; uint32 duration; //LOGD("c---> filename 好的 = %s", filename); if (iFs.Connect() != 0) { LOGD("=======iFs.Connect failed========>\n"); return PVMFFailure; } oscl_wchar output[MAX_BUFF_SIZE]; oscl_UTF8ToUnicode((const char *) filename, oscl_strlen((const char *) filename), (oscl_wchar *) output, MAX_BUFF_SIZE); if (0 != fileHandle.Open((oscl_wchar *) output, Oscl_File::MODE_READ | Oscl_File::MODE_BINARY, iFs)) { //LOGE("Could not open the input file for reading(Test: parse id3).\n"); return PVMFFailure; } fileHandle.Seek(0, Oscl_File::SEEKSET); pvId3Param.ParseID3Tag(&fileHandle); fileHandle.Close(); iFs.Close(); //Get the frames information from ID3 library PvmiKvpSharedPtrVector framevector; pvId3Param.GetID3Frames(framevector); uint32 num_frames = framevector.size(); for (uint32 i = 0; i < num_frames; i++) { const char *key = framevector[i]->key; bool isUtf8 = false; bool isIso88591 = false; // type should follow first semicolon const char *type = strchr(key, ';'); if (type == NULL) continue; type++; char tracknumkeybuf[100]; if (strncmp(key, "track-info/track-number;", 24) == 0) { // Java expects the track number key to be called "tracknumber", so // construct a temporary one here. snprintf(tracknumkeybuf, sizeof(tracknumkeybuf), "tracknumber;%s", type); key = tracknumkeybuf; } const char *value = framevector[i]->value.pChar_value; // KVP_VALTYPE_UTF8_CHAR check must be first, since KVP_VALTYPE_ISO88591_CHAR // is a substring of KVP_VALTYPE_UTF8_CHAR. // Similarly, KVP_VALTYPE_UTF16BE_WCHAR must be checked before KVP_VALTYPE_UTF16_WCHAR if (oscl_strncmp(type, KVP_VALTYPE_UTF8_CHAR, KVP_VALTYPE_UTF8_CHAR_LEN) == 0) { isUtf8 = true; } else if ( oscl_strncmp(type, KVP_VALTYPE_ISO88591_CHAR, KVP_VALTYPE_ISO88591_CHAR_LEN) == 0) { isIso88591 = true; } if (isUtf8) { // validate to make sure it is legal utf8 uint32 valid_chars; if (oscl_str_is_valid_utf8((const uint8 *) value, valid_chars)) { // utf8 can be passed through directly //LOGD("c---> key(utf8) = %s ; value = %s", key, value); if (!client.handleStringTag(key, value)) goto failure; } else { // treat as ISO-8859-1 if UTF-8 fails isIso88591 = true; } } if (isIso88591) { size_t iInLen = strlen(value); char sOutBuf[100]; size_t iOutLen = 100; memset(sOutBuf, 0x00, 100); ChangeCode("GBK", "UTF-8", value, &iInLen, sOutBuf, &iOutLen); //LOGD("c---> key(gbk) = %s ; value = %s", key, sOutBuf); if (!client.handleStringTag(key, sOutBuf)) goto failure; } // treat it as iso-8859-1 and our native encoding detection will try to // figure out what it is /* if (isIso88591) { // convert ISO-8859-1 to utf8, worse case is 2x inflation const unsigned char *src = (const unsigned char *) value; char *temp = (char *) alloca(strlen(value) * 2 + 1); if (temp) { char *dest = temp; unsigned int uch; while ((uch = *src++) != 0) { if (uch & 0x80) { *dest++ = (uch >> 6) | 0xc0; *dest++ = (uch & 0x3f) | 0x80; } else *dest++ = uch; } *dest = 0; LOGD("c---> key(iso) = %s ; value = %s", key, temp); //if (!client.addStringTag(key, temp)) goto failure; } }*/ // not UTF-8 or ISO-8859-1, try wide char formats if (!isUtf8 && !isIso88591 && (oscl_strncmp(type, KVP_VALTYPE_UTF16BE_WCHAR, KVP_VALTYPE_UTF16BE_WCHAR_LEN) == 0 || oscl_strncmp(type, KVP_VALTYPE_UTF16_WCHAR, KVP_VALTYPE_UTF16_WCHAR_LEN) == 0)) { // convert wchar to utf8 // the id3parcom library has already taken care of byteswapping const oscl_wchar *src = framevector[i]->value.pWChar_value; int srcLen = oscl_strlen(src); // worse case is 3 bytes per character, plus zero termination int destLen = srcLen * 3 + 1; char *dest = (char *) alloca(destLen); if (oscl_UnicodeToUTF8(src, oscl_strlen(src), dest, destLen) > 0) { //LOGD("c---> key(!utf8 && !iso) = %s ; value = %s", key, dest); if (!client.handleStringTag(key, dest)) goto failure; } } else if (oscl_strncmp(type, KVP_VALTYPE_UINT32, KVP_VALTYPE_UINT32_LEN) == 0) { char temp[20]; snprintf(temp, sizeof(temp), "%d", (int) framevector[i]->value.uint32_value); //LOGD("c---> key() = %s ; value = %s", key, temp); if (!client.handleStringTag(key, temp)) goto failure; } else { //LOGE("unknown tag type %s for key %s\n", type, key); } } // extract non-ID3 properties below { OSCL_wHeapString<OsclMemAllocator> mp3filename(output); MP3ErrorType err; IMpeg3File mp3File(mp3filename, err); if (err != MP3_SUCCESS) { //LOGE("IMpeg3File constructor returned %d for %s\n", err, filename); return err; } err = mp3File.ParseMp3File(); if (err != MP3_SUCCESS) { //LOGE("IMpeg3File::ParseMp3File returned %d for %s\n", err, filename); return err; } char buffer[20]; duration = mp3File.GetDuration(); sprintf(buffer, "%d", duration); LOGD("c---> duration = %s", "duration"); //if (!client.addStringTag("duration", buffer)) goto failure; } return PVMFSuccess; failure: return PVMFFailure; }