Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: MythTV: Dev

LastFM support in MythMusic

 

 

First page Previous page 1 2 Next page Last page  View All MythTV dev RSS feed   Index | Next | Previous | View Threaded


kormoc at gmail

Feb 25, 2008, 12:30 AM

Post #26 of 43 (3055 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

On Sun, Feb 24, 2008 at 11:36 PM, Willem Ligtenberg
<wligtenberg [at] gmail> wrote:
> Isn't MD5 independent of what the bytes represent?

It's very dependent, as it's a calculation based on the bytes in the file.
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


wligtenberg at gmail

Feb 25, 2008, 1:44 AM

Post #27 of 43 (3041 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

Well, I think we mean the same, it is dependent on the value of the
byte, but not on whether it is music, video or text. Right?

Willem

On Mon, Feb 25, 2008 at 9:30 AM, Rob Smith <kormoc [at] gmail> wrote:
> On Sun, Feb 24, 2008 at 11:36 PM, Willem Ligtenberg
> <wligtenberg [at] gmail> wrote:
> > Isn't MD5 independent of what the bytes represent?
>
> It's very dependent, as it's a calculation based on the bytes in the file.
>
>
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev [at] mythtv
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


nigel at ind

Feb 25, 2008, 10:37 AM

Post #28 of 43 (3030 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

> What do you mean with an AVMD5?

Look at the header:

% cat src/mythtv/libs/libavutil/md5.h
...
struct AVMD5;

void av_md5_init(struct AVMD5 *ctx);
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int
len);
void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);

#endif /* FFMPEG_MD5_H */


I'm assuming that context is a variable
that you are passing to these functions?

--
Nigel Pearson, nigel [at] ind| $50 million worth of
Telstra Net. Eng., Sydney, Australia | hardware and you didn't
Office: 9202 3900 Fax: 9261 3912 | think we'd throw in a GPS?
Mobile: 0408 664435 Home: 9792 6998 | - Jonas, Bionic Woman


_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


wligtenberg at gmail

Feb 26, 2008, 2:43 AM

Post #29 of 43 (3023 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

Well, with the risk of seeming stupid.
I will admit that this is my first C++ coding in a larger project. The
other stuff I did were my own small project where I could do
everything the way I wanted it.
This time I had my md5 functionality working using a library, but I
have found out that the devvers don't really like to include many
libraries let alone for only one function.
I can understand that of course.
But now I want to reuse the md5 function used in avutils.
It now compiles if I include the following header:
#include <mythtv/ffmpeg/md5.h>
Although this obviously generates a runtime error, because I haven't
linked anything yet. My question is now what do I have to add in the
makefile (or rather somewhere else, so that qmake makes the correct
makefile) so that it will link as it should?
I have tried linking to ffmpeg, but that doesn't work.
Thanks for the help,

Willem

On Mon, Feb 25, 2008 at 7:37 PM, Nigel Pearson <nigel [at] ind> wrote:
>
> > What do you mean with an AVMD5?
>
> Look at the header:
>
> % cat src/mythtv/libs/libavutil/md5.h
> ...
> struct AVMD5;
>
> void av_md5_init(struct AVMD5 *ctx);
> void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int
> len);
> void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
> void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
>
> #endif /* FFMPEG_MD5_H */
>
>
> I'm assuming that context is a variable
> that you are passing to these functions?
>
> --
> Nigel Pearson, nigel [at] ind| $50 million worth of
> Telstra Net. Eng., Sydney, Australia | hardware and you didn't
> Office: 9202 3900 Fax: 9261 3912 | think we'd throw in a GPS?
> Mobile: 0408 664435 Home: 9792 6998 | - Jonas, Bionic Woman
>
>
>
>
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev [at] mythtv
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


mythtv at dsl

Feb 26, 2008, 3:04 AM

Post #30 of 43 (3016 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

Willem Ligtenberg wrote:
> Well, with the risk of seeming stupid.
> I will admit that this is my first C++ coding in a larger project. The
> other stuff I did were my own small project where I could do
> everything the way I wanted it.
> This time I had my md5 functionality working using a library, but I
> have found out that the devvers don't really like to include many
> libraries let alone for only one function.
> I can understand that of course.
> But now I want to reuse the md5 function used in avutils.
> It now compiles if I include the following header:
> #include <mythtv/ffmpeg/md5.h>
> Although this obviously generates a runtime error, because I haven't
> linked anything yet. My question is now what do I have to add in the
> makefile (or rather somewhere else, so that qmake makes the correct
> makefile) so that it will link as it should?
> I have tried linking to ffmpeg, but that doesn't work.
> Thanks for the help,
>
> Willem
>

Did you try the suggestion by Anduin and wrap the include in extern "C"
like this?

extern "C" {
#include <mythtv/ffmpeg/md5.h>
}


Paul H.
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


wligtenberg at gmail

Feb 26, 2008, 5:36 AM

Post #31 of 43 (3014 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

I actually forgot that... sorry.
But I have just tried and then it doesn't whine about not finding an
object, but it seg faults and dumps the core...
Any ideas on that?

Thanks,

Willem

On Tue, Feb 26, 2008 at 12:04 PM, Paul Harrison <mythtv [at] dsl> wrote:
>
> Willem Ligtenberg wrote:
> > Well, with the risk of seeming stupid.
> > I will admit that this is my first C++ coding in a larger project. The
> > other stuff I did were my own small project where I could do
> > everything the way I wanted it.
> > This time I had my md5 functionality working using a library, but I
> > have found out that the devvers don't really like to include many
> > libraries let alone for only one function.
> > I can understand that of course.
> > But now I want to reuse the md5 function used in avutils.
> > It now compiles if I include the following header:
> > #include <mythtv/ffmpeg/md5.h>
> > Although this obviously generates a runtime error, because I haven't
> > linked anything yet. My question is now what do I have to add in the
> > makefile (or rather somewhere else, so that qmake makes the correct
> > makefile) so that it will link as it should?
> > I have tried linking to ffmpeg, but that doesn't work.
> > Thanks for the help,
> >
> > Willem
> >
>
> Did you try the suggestion by Anduin and wrap the include in extern "C"
> like this?
>
> extern "C" {
>
> #include <mythtv/ffmpeg/md5.h>
> }
>
>
> Paul H.
>
>
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev [at] mythtv
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


mythtv at dsl

Feb 26, 2008, 6:46 AM

Post #32 of 43 (3021 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

Willem Ligtenberg wrote:
> I actually forgot that... sorry.
> But I have just tried and then it doesn't whine about not finding an
> object, but it seg faults and dumps the core...
> Any ideas on that?
>
> Thanks,
>
> Willem
>
>

Some code showing us how you are calling av_md5_sum() will help.

Also if you can get a backtrace it will tell you exactly where it's
segfaulting which is often enough to see what you have done wrong..

Paul H.
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


wligtenberg at gmail

Feb 26, 2008, 7:04 AM

Post #33 of 43 (3026 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

I have created an extra method:
uint8_t *my_md5(QString string)
{
uint8_t *md5val;
uint8_t *c_string = (uint8_t*)string.toUInt();
av_md5_sum(md5val, c_string, string.length());
return md5val;
}

And I call this method as follows:
uint8_t *test = my_md5(authtoken.utf8());
cout << *test << endl;

Cheers,

Willem

On Tue, Feb 26, 2008 at 3:46 PM, Paul Harrison <mythtv [at] dsl> wrote:
> Willem Ligtenberg wrote:
> > I actually forgot that... sorry.
> > But I have just tried and then it doesn't whine about not finding an
> > object, but it seg faults and dumps the core...
> > Any ideas on that?
> >
> > Thanks,
> >
> > Willem
> >
> >
>
> Some code showing us how you are calling av_md5_sum() will help.
>
> Also if you can get a backtrace it will tell you exactly where it's
> segfaulting which is often enough to see what you have done wrong..
>
>
>
> Paul H.
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev [at] mythtv
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


mythtv at dsl

Feb 26, 2008, 7:23 AM

Post #34 of 43 (3019 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

Willem Ligtenberg wrote:
> I have created an extra method:
> uint8_t *my_md5(QString string)
> {
> uint8_t *md5val;
> uint8_t *c_string = (uint8_t*)string.toUInt();
> av_md5_sum(md5val, c_string, string.length());
> return md5val;
> }
>
> And I call this method as follows:
> uint8_t *test = my_md5(authtoken.utf8());
> cout << *test << endl;
>
> Cheers,
>
> Willem
>

The problem is here:-

uint8_t *c_string = (uint8_t*)string.toUInt();

That converts the string to an unsigned integer what you want is a
pointer to the data that represents the string. Something like this:

uint8_t *c_string = (uint8_t*)string.ascii();
or
uint8_t *c_string = (uint8_t*)string.local8bit();

should work.

Paul H.



_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


wligtenberg at gmail

Feb 26, 2008, 8:02 AM

Post #35 of 43 (3024 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

uint8_t *c_string = (uint8_t*)string.ascii();

Also results in a core dump...

or
uint8_t *c_string = (uint8_t*)string.local8bit();

QString doesn't have the function local8bit().

So, it still doesn't work...
Thanks though,

Willem

On Tue, Feb 26, 2008 at 4:23 PM, Paul Harrison <mythtv [at] dsl> wrote:
> Willem Ligtenberg wrote:
> > I have created an extra method:
> > uint8_t *my_md5(QString string)
> > {
> > uint8_t *md5val;
> > uint8_t *c_string = (uint8_t*)string.toUInt();
> > av_md5_sum(md5val, c_string, string.length());
> > return md5val;
> > }
> >
> > And I call this method as follows:
> > uint8_t *test = my_md5(authtoken.utf8());
> > cout << *test << endl;
> >
> > Cheers,
> >
> > Willem
> >
>
> The problem is here:-
>
>
> uint8_t *c_string = (uint8_t*)string.toUInt();
>
> That converts the string to an unsigned integer what you want is a
> pointer to the data that represents the string. Something like this:
>
> uint8_t *c_string = (uint8_t*)string.ascii();
> or
> uint8_t *c_string = (uint8_t*)string.local8bit();
>
> should work.
>
>
>
> Paul H.
>
>
>
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev [at] mythtv
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


mythtv at dsl

Feb 26, 2008, 8:25 AM

Post #36 of 43 (3020 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

Willem Ligtenberg wrote:
> uint8_t *c_string = (uint8_t*)string.ascii();
>
> Also results in a core dump...
>
> or
> uint8_t *c_string = (uint8_t*)string.local8bit();
>
> QString doesn't have the function local8bit().
>
> So, it still doesn't work...
> Thanks though,
>
> Willem
>
>

Sorry that should be local8Bit()

Also just noticed that md5val is uninitialized so is pointing to some
random address so you need to allocate the memory used something like this:-

uint8_t *md5val = malloc(8);

Paul H.
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


mythtv at dsl

Feb 26, 2008, 8:32 AM

Post #37 of 43 (3020 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

Willem Ligtenberg wrote:
> uint8_t *c_string = (uint8_t*)string.ascii();
>
> Also results in a core dump...
>
> or
> uint8_t *c_string = (uint8_t*)string.local8bit();
>
> QString doesn't have the function local8bit().
>
> So, it still doesn't work...
> Thanks though,
>
> Willem
>
>

Sorry that should be local8Bit()

Also just noticed that md5val is uninitialized so is pointing to some
random address so you need to allocate the memory used something like this:-

uint8_t *md5val = malloc(8);

Paul H.
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


awithers at anduin

Feb 26, 2008, 9:30 AM

Post #38 of 43 (3014 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

> uint8_t *md5val = malloc(8);

16

--
Anduin Withers

_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


mythtv at dsl

Feb 26, 2008, 9:55 AM

Post #39 of 43 (3019 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

Anduin Withers wrote:
>> uint8_t *md5val = malloc(8);
>>
>
> 16
>
> --
> Anduin Withers
>

The test example in md5.c passes an uint64_t which would be 8 bytes
would it not?

uint64_t md5val;
av_md5_sum( (uint8_t*)&md5val, in, 1000); printf("%"PRId64"\n", md5val);

Paul H.
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


awithers at anduin

Feb 26, 2008, 10:32 AM

Post #40 of 43 (3020 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

> I have created an extra method:
> uint8_t *my_md5(QString string)
> {
> uint8_t *md5val;
> uint8_t *c_string = (uint8_t*)string.toUInt();
> av_md5_sum(md5val, c_string, string.length());
> return md5val;
> }
> [...]
> cout << *test << endl;

You probably do not want to do that, it will output only the first byte, you
definitely do not want to "cout << test", the returned data is 16 bytes of
binary data, there is no null termination (and would be gibberish anyway).

Personally I'd return a std::vector<uint8_t>, you incur the tremendous cost
of a copy but you don't need to remember to free()/delete.

std::vector<uint8_t> my_md5(const QString &s)
{
std::vector<uint8_t> md5val(16);
QCString cs = s.utf8();
av_md5_sum(&md5val[0], reinterpret_cast<const uint8_t *>(cs.data()),
cs.length());
return md5val;
}

You should spend some time thinking about the encoding of the string. If you
are comparing you need to ensure both sources agree on the encoding before
the digest is generated.

--
Anduin Withers

_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


awithers at anduin

Feb 26, 2008, 10:52 AM

Post #41 of 43 (3012 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

> The test example in md5.c passes an uint64_t which would be 8 bytes
> would it not?
>
> uint64_t md5val;
> av_md5_sum( (uint8_t*)&md5val, in, 1000); printf("%"PRId64"\n", md5val);

It would, the problem is in assuming the test is valid. The test stomps the
stack (print i before the first call to av_md5_sum, then after).

In av_md5_final() dst is treated as an array of four uint32_t (this also
matches the expected MD5 hex string of 32 characters).

--
Anduin Withers

_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


wligtenberg at gmail

Feb 27, 2008, 6:23 AM

Post #42 of 43 (2988 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

OK, well with the malloc in place, it now actually works.
I do not have a vector implementation, yet...
But I do know the encoding that should be used, namely utf8, I already
know how to convert the QString to utf8, so that is no problem.
But the thing I really want is a hexadecimal representation of that
binary data and cast that to a string, just like the normal md5sum
would do.
Any ideas on how to accomplish that?
I know casting won't work :)

Thanks,

Willem

On Tue, Feb 26, 2008 at 7:32 PM, Anduin Withers <awithers [at] anduin> wrote:
> > I have created an extra method:
> > uint8_t *my_md5(QString string)
> > {
> > uint8_t *md5val;
> > uint8_t *c_string = (uint8_t*)string.toUInt();
> > av_md5_sum(md5val, c_string, string.length());
> > return md5val;
> > }
> > [...]
> > cout << *test << endl;
>
> You probably do not want to do that, it will output only the first byte, you
> definitely do not want to "cout << test", the returned data is 16 bytes of
> binary data, there is no null termination (and would be gibberish anyway).
>
> Personally I'd return a std::vector<uint8_t>, you incur the tremendous cost
> of a copy but you don't need to remember to free()/delete.
>
> std::vector<uint8_t> my_md5(const QString &s)
> {
> std::vector<uint8_t> md5val(16);
> QCString cs = s.utf8();
> av_md5_sum(&md5val[0], reinterpret_cast<const uint8_t *>(cs.data()),
> cs.length());
> return md5val;
> }
>
> You should spend some time thinking about the encoding of the string. If you
> are comparing you need to ensure both sources agree on the encoding before
> the digest is generated.
>
> --
> Anduin Withers
>
>
>
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev [at] mythtv
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>
_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


awithers at anduin

Feb 27, 2008, 10:49 AM

Post #43 of 43 (2980 views)
Permalink
Re: LastFM support in MythMusic [In reply to]

> Any ideas on how to accomplish that?
> I know casting won't work :)

I'm still going to recommend that for things like this you look at #qt or
for a non-Qt answer, ##C++ (a hint if you look at the QString docs long
enough one possible way becomes impossible to ignore).

--
Anduin Withers

_______________________________________________
mythtv-dev mailing list
mythtv-dev [at] mythtv
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev

First page Previous page 1 2 Next page Last page  View All MythTV dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.